HTML DOM clearTimeout() ·½·¨

¶¨ÒåºÍÓ÷¨

clearTimeout() ·½·¨¿ÉÈ¡ÏûÓÉ setTimeout() ·½·¨ÉèÖÃµÄ timeout¡£

Óï·¨

clearTimeout(id_of_settimeout)
²ÎÊý ÃèÊö
id_of_settimeout ÓÉ setTimeout() ·µ»ØµÄ ID Öµ¡£¸ÃÖµ±êʶҪȡÏûµÄÑÓ³ÙÖ´ÐдúÂë¿é¡£

ʵÀý

ÏÂÃæµÄÀý×ÓÿÃëµ÷ÓÃÒ»´Î timedCount() º¯Êý¡£ÄúÒ²¿ÉÒÔʹÓÃÒ»¸ö°´Å¥À´ÖÕÖ¹Õâ¸ö¶¨Ê±ÏûÏ¢£º

<html>
<head>
<script type="text/javascript">
var c=0
var t
function 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>
VUE