<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jquery addClass removeClass</title> <style> .intro{ font-size:120%; color:red; } </style> <script src="js/jquery-3.2.1.js"></script> <script> $(function(){ $("button:first").click(function(){ $("p:first").addClass("intro"); }); $("#removeClass").click(function(){ $("p:first").removeClass("intro"); // $(".intro").removeClass("intro"); }); }); // 定义和用法 // addClass() 方法向被选元素添加一个或多个类。 // 该方法不会移除已存在的 class 属性,仅仅添加一个或多个 class 属性。 // 提示:如需添加多个类,请使用空格分隔类名。 // removeClass() 方法从被选元素移除一个或多个类。 // 注释:如果没有规定参数,则该方法将从被选元素中删除所有类。 </script> </head> <body> <h1>标题</h1> <p>段落1。</p> <p>段落2。</p> <button>添加样式</button> <button id="removeClass">移除样式</button> </body> </html>
jquery addClass removeClass.html
猜你喜欢
转载自blog.csdn.net/weixin_42193179/article/details/88573181
今日推荐
周排行