标签:
<html> <head> <meta charset="utf-8"> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".box1").toggle(function(){ $("p:first").addClass(‘main‘);//addClass如果增加的样式与前面冲突,则覆盖前面的样式 },function(){ $("p:first").removeClass(‘main‘); }); $(".box2").click(function(){ if($(".intro").is(".main")){//is函数判断是否有类main alert(‘hello‘); }else{ alert(‘null‘); } }); }); </script> <style type="text/css"> .intro { font-size:120%; color:red; } .main { font-size:90%; color:blue; } </style> </head> <body> <h1>This is a heading</h1> <p class="intro">This is a paragraph.</p> <p>This is another paragraph.</p> <button class="box1">改变第一个段落的类</button> <button class="box2">提交</button> </body> </html>
标签:
原文地址:http://www.cnblogs.com/xiaozhumaopao/p/5767598.html