Home > Article > Web Front-end > Detailed explanation of the use and definition of clearInterval() method in JavaScript
Friends who often use JavaScript should have some understanding of the clearInterval() method. It can cancel the timer set by the setInterval() method. Some friends may not understand it very well. Today I will introduce to you the definition of the clearInterval() method. and usage!
This method can cancel the timer set by the setInterval() method.
The parameter of this method must be the return value of the corresponding setInerval() method to be canceled.
Click to see more properties and methods of the window object.
Syntax structure:
clearInterval(id)
Parameter list:
Browser support:
(1). IE browser supports this attribute.
(2).Firefox browser supports this attribute.
(3).Opera browser supports this attribute.
(4).Chrome browser supports this attribute.
(5).Safria browser supports this method.
Code example:
<!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; } #btp{ 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> <p id="num"></p> <p id="btp"><button id="bt">点击取消</button></p> </body> </html>
Summary:
This article uses examples to introduce the use of the clearInterval() method in JavaScript. I believe many friends have a certain understanding of this! , hope it will be helpful to your work!
Related recommendations:
Sample code for using setInterval and clearInterval
The calling method of setinterval() and clearInterval() JS functions
The definition and usage of js clearInterval() method
The above is the detailed content of Detailed explanation of the use and definition of clearInterval() method in JavaScript. For more information, please follow other related articles on the PHP Chinese website!