<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
var num=0;
function numCount(){
document.getElementById('txt').value=num;
num=num+1;
setTimeout("numCount()",1000);
}
</script>
</head>
<body>
<form>
<input type="text" id="txt" />
<input type="button" value="Start" onClick="numCount()" />
</form>
</body>
</html>为什么一直点击按钮时,计数会加快?
4 回答
mov1er
TA贡献2条经验 获得超0个赞
函数内的代码改成
clearTimeout(timer)
document.getElementById('txt').value=num;
num=num+1;
var timer=setTimeout("numCount()",1000);
添加回答
举报
0/150
提交
取消