第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

計時器多次點擊,每點擊一個開始就多一個計時器,而多個計時器同時工作的時候,每次單擊只能停止一個計時器。

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


正在回答

2 回答

解決多開定時器的方法只有一個,就是讓開關(guān)點擊完一次不能再次點擊。

憑老夫多年經(jīng)驗給你2段代碼,你把它們加上??document.getElementById("myButton").disabled = true;這段加在定時器打開的函數(shù)里面。。document.getElementById("myButton").disabled = false;這段加在定時器停止的函數(shù)里面。。? 順便你給打開定時的button起一個id=myButton

3 回復(fù) 有任何疑惑可以回復(fù)我~
#1

天心皓月 提問者

非常感謝!
2018-06-22 回復(fù) 有任何疑惑可以回復(fù)我~

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>計時器</title>

<script type="text/javascript">


? var num=0;

? var i;

? var a = true;

function add(){

document.getElementById('count').value=num;

num=num+1;

i=setTimeout("add()",1000);

}

? function startCount(){

? if(a){

add()

? ? ? }

? a = false;

? }

??


? function stopCount(){

if(a==false){

clearTimeout(i);

}

a = true;

? }


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

這是我之前學(xué)習(xí)時寫的代碼,這個就是不變button的

2 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

計時器多次點擊,每點擊一個開始就多一個計時器,而多個計時器同時工作的時候,每次單擊只能停止一個計時器。

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號