<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<script>
var i=0;
var start;
window.onload=function(){
document.getElementById("b").onclick=function(){
start=setInterval(function(){
i++;
document.getElementById("a").innerHTML=i;
},1000);
}
document.getElementById("c").onclick=function(){
clearInterval(start);
}
}
</script>
<body>
<div id="a">
</div>
<button id="b">开始计时</button>
<button id="c">停止计时</button>
</body>
</html>
通过setInterval和clearInterval实现的计时效果
最新推荐文章于 2024-10-15 19:03:52 发布