[英]JavaScript - how to run setInterval() only 1 time
<button onClick="increase = setInterval(increasing, 400);
clearInterval(decrease);"><b>Sicaklik Arttir (+)</b>
</button>
<button onClick="clearInterval(increase);
clearInterval(decrease);"><b>Stop</b
</button>
<button onClick="decrease = setInterval(decreasing, 400);
clearInterval(increase)"><b>Sicaklik Azalt (-)</b>
</button>
我有包含setInterval
按鈕。 當我按下按鈕時, setInterval
被調用,但是當我再次按下時, setInterval
被再次調用,而我無法停止它。
如何停止?
我只想運行setInterval
一次。
有setTimeout方法,一次僅調用一次。
setTimeout(increasing, 400)
要清除超時,請使用clearTimeout方法。
在第二次單擊按鈕之前和超時400秒之前檢查返回值,
if(! increase)
increase = setTimeout(increasing, 400);
然后清除超時:
clearTimeout(increase);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.