[JavaScript] jQuery给多个不同的元素添加class →→→→→进入此内容的聊天室

来自 , 2019-12-21, 写在 JavaScript, 查看 113 次.
URL http://www.code666.cn/view/ab49ef78
  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").addClass("blue");
  10.     $("div").addClass("important");
  11.   });
  12. });
  13. </script>
  14. <style type="text/css">
  15. .important
  16. {
  17. font-weight:bold;
  18. font-size:xx-large;
  19. }
  20. .blue
  21. {
  22. color:blue;
  23. }
  24. </style>
  25. </head>
  26. <body>
  27.  
  28. <h1>Heading 1</h1>
  29. <h2>Heading 2</h2>
  30. <p>This is a paragraph.</p>
  31. <p>This is another paragraph.</p>
  32. <div>This is some important text!</div>
  33. <br>
  34. <button>Add classes to elements</button>
  35.  
  36. </body>
  37. </html>
  38.  
  39. //javascript/8115

回复 "jQuery给多个不同的元素添加class"

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

captcha