您的位置:首页 > 其它

正则表达式基础学习一

2013-04-17 21:08 162 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
</head>
<body>
<div class="box box-link in-home"></div>
<div class="box-link in-home box"></div>
<div class="box-link box in-home"></div>
<div class="box"></div>
<div class="box-link in-home"></div>
<script type="text/javascript">
var reg = /(^| )box( |$)/;
var elems = document.getElementsByTagName("div");
for (var i = 0; i < elems.length; i++) {
//console.log(elems[i].className);
if (elems[i].className.match(reg) !== null) {
console.log("true");
} else {
console.log("false");
}
};
</script>
</body>
</html>


检测div里的class是否存在box
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: