亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長(zhǎng)資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    JavaScript怎么刪除延時(shí)器

    JavaScript刪除延時(shí)器的方法:1、使用“clearInterval(id)”語(yǔ)句,可以刪除由setInterval()定義的延時(shí)器;2、使用“clearTimeout(id)”語(yǔ)句,可刪除由setTimeout()定義的延時(shí)器。

    JavaScript怎么刪除延時(shí)器

    本教程操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版、Dell G3電腦。

    JavaScript 延時(shí)器,又稱定時(shí)器,有時(shí)也稱為“計(jì)時(shí)器”,用來(lái)在經(jīng)過(guò)指定的時(shí)間后執(zhí)行某些任務(wù),類似于我們生活中的鬧鐘。

    在 JavaScript 中,我們可以利用延時(shí)器來(lái)延遲執(zhí)行某些代碼,或者以固定的時(shí)間間隔重復(fù)執(zhí)行某些代碼。

    JavaScript 中提供了兩種方式來(lái)設(shè)置定時(shí)器,分別是 setTimeout() 和 setInterval();而對(duì)應(yīng)的刪除延時(shí)器的方法也有兩種:

    • clearInterval() 取消由 setInterval() 設(shè)置的 timeout。

    • clearTimeout() 取消由 setTimeout() 方法設(shè)置的 timeout。

    clearInterval()

    clearInterval() 方法可取消由 setInterval() 設(shè)置的 timeout。

    語(yǔ)法:

    clearInterval(id)

    clearInterval() 方法的參數(shù)必須是由 setInterval() 返回的 ID 值。

    示例:

    <html> <body>  <input type="text" id="clock" size="35" /> <script language=javascript> var int=self.setInterval("clock()",50) function clock()   {   var t=new Date()   document.getElementById("clock").value=t   } </script> </form> <button onclick="int=window.clearInterval(int)"> Stop interval</button>  </body> </html>

    clearTimeout()

    clearTimeout() 方法可取消由 setTimeout() 方法設(shè)置的 timeout。

    語(yǔ)法:

    clearTimeout(id)

    clearInterval() 方法的參數(shù)必須是由 setTimeout() 返回的 ID 值。

    示例:

    <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>

    【推薦學(xué)習(xí):javascript高級(jí)教程】

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)