jQuery实现为一个P元素增加或删除样式类
为一个P元素增加或删除样式类,鼠标放在上面变红加粗,鼠标移开恢复原状。
1 <script> 2 3 $(document).ready(function(){ 4 $("button").click(function(){ 5 $("h1,h2,p").addClass("blue"); 6 $("div").addClass("important"); 7 }); 8 $("#p1").mouseenter(function(){ 9 $(this).addClass("red"); 10 }); 11 $("#p1").mouseleave(function(){ 12 $(this).removeClass("red"); 13 }); 14 15 }); 16 </script> 17 <style type="text/css"> 18 .important 19 { 20 font-weight:bold; 21 font-size:large; 22 } 23 .blue 24 { 25 color:blue; 26 } 27 .red{ 28 color:red; 29 font-weight:bold; 30 } 31 </style>

浙公网安备 33010602011771号