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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

關(guān)于setTimeout()多次點(diǎn)擊速度飆升問題!

<!DOCTYPE HTML>

<html>

<head>

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

<title>計(jì)時(shí)器</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>

為什么多次點(diǎn)擊Start速度就會(huì)加快?哪位大神能給個(gè)終極解釋?跪求!

正在回答

2 回答

<!DOCTYPE HTML>

<html>

<head>

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

<title>計(jì)時(shí)器</title>


<script type="text/javascript">

? var num=0;

? var i;

? var flag=false;

??

//增加一個(gè)布爾變量用于存儲(chǔ)值代表start是否開始

//這個(gè)方法要置于循環(huán)體外

? function flag1(){

? ? if(flag==false){

? ? ? ?startCount();

? ? ? ?flag=true;

? ? }else{

? ? ? ?return 0;

? ? }

? }

? function startCount(){

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

? ? num=num+1;

? ? i=setTimeout("startCount()",1000);

? }

? function stopCount(){

? ? clearTimeout(i);

? ? flag=false;

? }

</script>

</head>

<body>

? <form>

? ? <input type="text" id="count" />

? ? <input type="button" value="Start" onclick="flag1()" />

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

? </form>

</body>

</html>



增加一個(gè)開關(guān)裝置即可解決點(diǎn)一次start鍵就多一個(gè)計(jì)數(shù)器增加num值的問題。

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

因?yàn)槟阍趕tartCount中又調(diào)用了它本身,所以你多次點(diǎn)擊之后,是多個(gè)計(jì)時(shí)器同時(shí)運(yùn)行的,比如點(diǎn)第一次是一個(gè)計(jì)時(shí)器,再點(diǎn)一下,就是兩個(gè)計(jì)時(shí)器,這時(shí)候每次就是+2,所以速度會(huì)不斷提升

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

舉報(bào)

0/150
提交
取消

關(guān)于setTimeout()多次點(diǎn)擊速度飆升問題!

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

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

幫助反饋 APP下載

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

公眾號(hào)

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