• 正则表达式基础学习一


     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

  • 相关阅读:
    JavaScript引用类型
    Java08_方法
    网络爬虫(一)
    openCV(四)——鼠标绘制
    openCV(三)——视频
    openCV(二)——基础绘制函数
    openCV(一) 读取保存图像
    JAVA07-数组
    JAVA06-while循环,do while循环
    JAVA05-switch多重选择
  • 原文地址:https://www.cnblogs.com/qzsonline/p/3027083.html
Copyright © 2020-2023  润新知