哪位大佬可以在旁边加个清空按钮吗?我试了好几次不知道咋做?,还有就是为啥我在startCount()函数中执行一次clearTimeout(i);还是没有解决”点击n次star后 数字狂增!“的问题呢?这是我的代码:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>计时器</title>
<script type="text/javascript">
var num=0;
var i;
function startCount(){
clearTimeout(i);
document.getElementById('count').value=num;
num=num+1;
i=setTimeout("startCount()",1000);
}
function stopCount(){
clearTimeout(i);
}
function clearAll(){
document.getElementById("count").value="";
}
</script>
</head>
<body>
<form>
<input type="text" id="count" />
<input type="button" value="Start" onclick="startCount()"/>
<input type="button" value="Stop" onclick="stopCount()"/>
<input type="reset" value="clear" onclick="clearAll()">
</form>
</body>
</html>
管你数字的是num不是count啊~你把clearall设成num=0就初始化了