window.clearInterval()方法

來源:互聯網
上載者:User

標籤:

clearInterval()方法的定義和用法:
此方法能夠取消setInterval()方法設定的定時器。
此方的參數必須是要取消的相應的setInerval()方法的傳回值。
點擊可參閱更多window對象的屬性和方法。
文法結構:

clearInterval(id)

參數列表:

id 必需。此id是setInerval()的傳回值,是此setInerval()方法的唯一標識。

瀏覽器支援:
1.IE瀏覽器支援此屬性。
2.Firefox瀏覽器支援此屬性。
3.Opera瀏覽器支援此屬性。
4.chrome瀏覽器支援此屬性。
代碼執行個體:

<!DOCTYPE HTML><html><head><meta charset="utf-8"/><meta name="author" content="http://www.softwhy.com/" /><title>window對象的clearInterval()方法 -螞蟻部落</title><style type="text/css">#num{  width:100px;  height:100px;  text-align:center;  line-height:100px;  background-color:green;  margin:50px auto 0px auto;  color:red;}#btdiv{  width:76px;  height:76px;  margin:0px auto;}</style><script type="text/javascript">var a=0;window.onload=function(){  var num=document.getElementById("num");  var bt=document.getElementById("bt");  function jisuan(){    num.innerHTML=a;    a=a+1;  }  var flag=setInterval(jisuan,1000);  bt.onclick=function(){    clearInterval(flag);  }}</script></head><body><div id="num"></div><div id="btdiv"><button id="bt">點擊取消</button></div></body></html>

以上代碼點擊按鈕可以取消數字自增效果。

原文地址是:clearInterval

window.clearInterval()方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.