<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <script> window.onload = function() { var a = 0; obtn1 = document.getElementById("btn1"); obtn2 = document.getElementById("btn2"); obtn1.onclick = function() { setTimeout(function rec() { document.getElementById("txt").value = a; a = a + 1; x = setTimeout(rec, 1000) }, 1000) } obtn2.onclick = function() { var b = 0; setTimeout(document.getElementById('txt').value=b, 0); clearTimeout(x); } } </script> </head> <body> <input type="text" name="text" id="txt" /> <input type="button" id="btn1" value="开始计时!" /> <input type="button" id="btn2" value="结束计时!" /> </body> </html>
为什么我点击结束计时之后,再次重新计时,不是从0开始,而是接着之前的数字开始计时? 请问问题出在哪儿了?怎么修改
千秋此意
相关分类