Blogger Information
Blog 16
fans 0
comment 1
visits 8489
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
自定义方法,实现通过类名获取对象集合
浅若夏沫
Original
516 people have browsed it
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>自定义方法,实现通过类名获取对象集合</title>
  8. <style>
  9. .one{
  10. width:500px;
  11. height:500px;
  12. background-color: rgb(112, 236, 168);
  13. line-height: 100px;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <div class="one">
  19. <div class="one1">111122</div>
  20. <div class="one2 one1">3333444</div>
  21. <div class="one1">5555666。</div>
  22. <div class="three">7777888</div>
  23. <div class="three2">999</div>
  24. </div>
  25. <script>
  26. var ones = document.getElementsByClassName('one1');
  27. console.log(ones);
  28. for(var i = 0; i < ones.length; i++){
  29. ones[i].style.backgroundColor="red";
  30. ones[i].style.color="blue";
  31. }
  32. </script>
  33. </body>
  34. </html>

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post