js点击多个div后再触发事件怎么写
1个回答
展开全部
<html>
<head >
<style>
div{border:1px solid #ccc;width:100px;height:100px;text-align:center;line-height:100px;margin:2px;float:left;}
</style>
<script>
function clickDiv(divObj) {
var divClickStatus = divObj.getAttribute("clickStatus");
if(null == divClickStatus || !divClickStatus){
divObj.style.border="1px solid red";
}else{
divObj.style.border="1px solid #ccc";
}
divObj.setAttribute("clickStatus",(null == divClickStatus || !divClickStatus))
if(checkAllClick()){alert("3个DIV都已经点击过了");}
}
function checkAllClick() {
var divList = document.getElementsByTagName("div");
for(var i in divList){
var div = divList[i];
if(!div || !div.tagName || "div" != div.tagName.toLowerCase()){continue;}
if(!div.getAttribute("clickStatus") || div.getAttribute("clickStatus") == null){return false;}
}
return true;
}
</script>
</head>
<body>
<div onclick="clickDiv(this)" >DIV1</div>
<div onclick="clickDiv(this)" >DIV2</div>
<div onclick="clickDiv(this)" >DIV3</div>
</body>
</html>
不晓得你要的是不是这个效果
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询