亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

按stop停不下來,而且時鐘不是一秒跳1秒,而是一秒跳3秒甚至5秒的數,總之很怪異。

<!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>

http://img1.sycdn.imooc.com//58003d660001e4ab06200396.jpg

正在回答

6 回答

?<input?type="button"?value="Start"?onClick("startCount()")?/>
????<input?type="button"?value="Stop"?onClick("stopCount()")??/>
????<!--這里onclick后面不是用“=”嗎?這括號目前我是沒見過有用過-->


1 回復 有任何疑惑可以回復我~

每點一次start按鈕,就會調用一次startCount()函數,所以計時速度就會加快。

如果想停止就,點相應次數的stop。

0 回復 有任何疑惑可以回復我~

function startCount(){
?clearTimeout(i);
?document.getElementById('count').value=num;
?num=num+1;
?i=setTimeout("startCount()",1000);
}

主要的原因是你在start里面沒有清除原來的定時器, 如果點擊多次之后, stop也需要點擊多次才會停止所有已開啟的定時器

3 回復 有任何疑惑可以回復我~

大概看了下,本身邏輯沒有問題,把下面的點擊事件后面改成"="試試

<input type="button" value="Start" onClick="startCount()" />

<input type="button" value="Stop" onClick="stopCount()" ?/>


0 回復 有任何疑惑可以回復我~

<!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>


0 回復 有任何疑惑可以回復我~

<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>


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

按stop停不下來,而且時鐘不是一秒跳1秒,而是一秒跳3秒甚至5秒的數,總之很怪異。

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號