正则表达式基础学习一

 

 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

posted @ 2013-04-17 21:08  小猩猩君  阅读(166)  评论(0编辑  收藏  举报