<!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 starcount(){
document.getElementById("txt").value = num;
num = num + 1;
i=setTimeout("starcount()",1000);
}
//setTimeout("starcount()",1000);
function stopcount(){
clearTimeout(i);
}
</script>
</head>
<body>
<form>
<input type="text" id="txt" />
<input type="button" value="start" onclick="startcount()" />
<input type="button" value="stop" onclick="stopcount()" />
</form>
</body>
</html>
function starcount(){
document.getElementById("txt").value = num;
num = num + 1;
i=setTimeout("starcount()",1000);
}
//setTimeout("starcount()",1000);
在你设置的这个函数里 startcount 拼写错误 少了个 "t"
随便起什么名字当然是没问题,但是你后面调用时候写的 <input type="button" value="start" onclick="startcount()" />其中onclick="startcount()"这句 要与前面你随便起的那个名字保持一致才可以哦