<!DOCTYPE html>
<html lang="en">
<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=0, 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開始。