求大佬解答
哪位大佬可以在旁邊加個清空按鈕嗎?我試了好幾次不知道咋做?,還有就是為啥我在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>
2017-04-25
管你數字的是num不是count啊~你把clearall設成num=0就初始化了