JavaScript Window对象ClearTimeout()方法
JavaScript ClearTimeout()方法用于清除SetTimeout()方法设置的计时器。
语法
clearTimeout(settimeout id)
JavaScript Window对象ClearTimeout()方法示例
<html> <head> <script type="text/javascript"> var c = 0; var t; var tsn = 0; function countTime() { document.getElementById('str').value = c; c = c + 1; t = setTimeout("countTime()", 1000); } function Timer() { if (!tsn) { tsn = 1; countTime(); } } function StopTime() { clearTimeout(t); tsn = 0; } </script> </head> <body> <form> <p> click button for start and stop</p> <textarea id="str"></textarea> <input type="button" value="Start" onclick="Timer()" /> <input type="button" value="stop" onclick="StopTime()" /> </form> </body> </html>
日期:2020-04-18 01:09:26 来源:oir作者:oir