點擊start和stop都沒有反應(yīng),是什么原因?
<!DOCTYPE HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>計時器計數(shù)</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>
2016-08-25
?? ??? ?document.getElementById("txt").value = num;
?? ??? ?num = num + 1;
?? ??? ?i=setTimeout("starcount()",1000);
?? ?}
?? ?//setTimeout("starcount()",1000);
在你設(shè)置的這個函數(shù)里 startcount 拼寫錯誤 少了個 "t"
2016-08-26