为什么点一下按钮,文本框的数字就只加一;;而我要效果是点一下按钮,文本框内容就从0开始自动计数,请问哪里写错了??????
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>计时器</title>
</head>
<script>
window.onload=function ()
{
var oTxt1=document.getElementById("txt1");
var oBtn1=document.getElementById("btn1");
var num=0;
oBtn1.onclick=function tt()
{
var time=setTimeout(function(){
num++;
oTxt1.value=num;
setTimeout(tt(),0);
},1000);
}
}
</script>
</head>
<body>
<form>
<input id="txt1" type="text" />
<input id="btn1" type="button" value="点击" />
</form>
</body>
</html>
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>计时器</title> </head> <script> window.onload=function () { var oTxt1=document.getElementById("txt1"); var oBtn1=document.getElementById("btn1"); var num=0; oBtn1.onclick=function tt() { var time=setTimeout(function(){ num++; oTxt1.value=num; setTimeout(tt(),0); },1000); } } </script> </head> <body> <form> <input id="txt1" type="text" /> <input id="btn1" type="button" value="点击" /> </form> </body> </html>