[JavaScript] jQuery通过toggleClass方法动态添加删除Class →→→→→进入此内容的聊天室

来自 , 2021-03-03, 写在 JavaScript, 查看 142 次.
URL http://www.code666.cn/view/8a0cd50e
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
  5. </script>
  6. <script>
  7. $(document).ready(function(){
  8.   $("button").click(function(){
  9.     $("h1,h2,p").toggleClass("blue");
  10.   });
  11. });
  12. </script>
  13. <style type="text/css">
  14. .blue
  15. {
  16. color:blue;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21.  
  22. <h1>Heading 1</h1>
  23. <h2>Heading 2</h2>
  24. <p>This is a paragraph.</p>
  25. <p>This is another paragraph.</p>
  26. <button>Toggle class</button>
  27. </body>
  28. </html>
  29.  
  30. //javascript/8118

回复 "jQuery通过toggleClass方法动态添加删除Class"

这儿你可以回复上面这条便签

captcha