
JavaScript中可以在点击事件上绑定函数,点击时执行函数,通过统计函数执行次数来统计点击次数。
JavaScript中统计点击次数:
<!DOCTYPE html>
<html>
<head>
<title>Document</title>
<style>
#Odiv{
margin:0 auto;
width: 200px;
height:200px;
background: yellow;
}
</style>
</head>
<body>
<div id="Odiv" onclick="show()">点击0次</div>
<script>
var time=0;
function show(){
if(time%2==0){
Odiv.style.background="pink";
console.log(time);
time++;
}else{
Odiv.style.background="yellow";
console.log(time);
time++;
}
document.getElementById('Odiv').innerHTML = "点击"+time+"次";
}
</script>
</body>
</html>预览看下吧!



网友评论文明上网理性发言 已有0人参与
发表评论: