<!DOCTYPE?HTML>
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8">
<title>計時器</title>
</head>
<script?type="text/javascript">
??var?num=0;
??var?i;
??function?startCount(){
????document.getElementById('count').value=num;
????num=num+1;
????i=setTimeout("startCount()",1000);
??}
??function?stopCount(){
??????clearTimeout(i);
??}
</script>
</head>
<body>
??<form>
????<input?type="text"?id="count"?/>
????<input?type="button"?value="Start"?onClick("startCount()")?/>
????<input?type="button"?value="Stop"?onClick("stopCount()")??/>
??</form>
</body>
</html>

2016-10-25
2016-10-19
每點一次start按鈕,就會調用一次startCount()函數,所以計時速度就會加快。
如果想停止就,點相應次數的stop。
2016-10-14
function startCount(){
?clearTimeout(i);
?document.getElementById('count').value=num;
?num=num+1;
?i=setTimeout("startCount()",1000);
}
主要的原因是你在start里面沒有清除原來的定時器, 如果點擊多次之后, stop也需要點擊多次才會停止所有已開啟的定時器
2016-10-14
大概看了下,本身邏輯沒有問題,把下面的點擊事件后面改成"="試試
<input type="button" value="Start" onClick="startCount()" />
<input type="button" value="Stop" onClick="stopCount()" ?/>
2016-10-14
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>計時器</title>
</head>
<script type="text/javascript">
var num=0;
function startCount(){
document.getElementById('count').value=num;
num=num+1;
i=setTimeout(startCount,1000);
}
setTimeout(startCount,1000);
function stopCount(){
? ? clearTimeout(i);
}
</script>
</head>
<body>
? <form>
? ? <input type="text" id="count" />
? ? <input type="button" value="Start" onClick("startCount()") />
? ? <input type="button" value="Stop" onClick("stopCount()") ?/>
? </form>
</body>
</html>
2016-10-14
<script?type="text/javascript">
??var?num=0;
??var?i;
??function?startCount(){
????document.getElementById('count').value=num;
? ?for(i=0;i<num.length;i++) {
? ?num=num+1;
????i=setTimeout("startCount()",1000);
??}
}
??function?stopCount(){
??????clearTimeout(i);
??}
</script>
</head>
<body>
??<form>
????<input?type="text"?id="count"?/>
????<input?type="button"?value="Start"?onClick("startCount()")?/>
????<input?type="button"?value="Stop"?onClick("stopCount()")??/>
??</form>
</body>
</html>