古詩詞大全網 - 成語解釋 - JS裏clearTimeout()方法是什麽方法?

JS裏clearTimeout()方法是什麽方法?

clearTimeout() 方法可取消由 setTimeout() 方法設置的 timeout 下面的例子每秒調用壹次 timedCount() 函數。您也可以使用壹個按鈕來終止這個定時消息: <html><head><script type="text/javascript">var c=0var tfunction timedCount() { document.getElementById('txt').value=c c=c+1 t=setTimeout("timedCount()",1000) }function stopCount() { clearTimeout(t) }</script></head><body><form><input type="button" value="Start count!" onClick="timedCount()"><input type="text" id="txt"><input type="button" value="Stop count!" onClick="stopCount()"></form></body></html>