1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
 5     <title>Document</title>
 6 </head>
 7 <body>
 8     <div class="box box-link in-home"></div>
 9     <div class="box-link in-home box"></div>
10     <div class="box-link box in-home"></div>
11     <div class="box"></div>
12     <div class="box-link in-home"></div>
13     <script type="text/javascript">
14     var reg = /(^| )box( |$)/;
15     var elems = document.getElementsByTagName("div");
16     for (var i = 0; i < elems.length; i++) {
17         //console.log(elems[i].className);
18         if (elems[i].className.match(reg) !== null) {
19             console.log("true");
20         } else {
21             console.log("false");
22         }
23     };
24     </script>
25 </body>
26 </html>

检测div里的class是否存在box

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
  • 2021-09-15
  • 2022-12-23
  • 2022-01-19
猜你喜欢
  • 2021-11-09
  • 2021-12-08
  • 2021-06-10
  • 2023-03-23
  • 2021-11-27
  • 2021-12-21
相关资源
相似解决方案