<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>计时器</title>
<script type="text/javascript">
var num=0;
function startCount() {
document.getElementById('count').value=num;
num=num+1;
setTimeout("starCount()",1000);
}
</script>
</head>
<body>
<form>
<input type="text" id="count" />
</form>
</body>
</html>
你要执行函数啊,不然写了函数干嘛用,在函数后面加上代码:setTimeout("startCount()",1000);
starCount改成stratCount,少写了个t
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>计时器</title> <script type="text/javascript"> var num=0; function startCount() { console.log(num); document.getElementById('count').value=num++; } setInterval("startCount()",1000); </script> </head> <body> <form> <input type="text" id="count" /> </form> </body> </html>
兄弟,你用的setTimeout函数只执行一次的,应该用setInterval