Home > Web Front-end > JS Tutorial > body text

Detailed explanation of the use and definition of clearInterval() method in JavaScript

黄舟
Release: 2017-12-04 09:44:04
Original
7440 people have browsed it

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)
Copy after login

Parameter list:

Parameters Description
idRequired. This id is the return value of setInerval() and is the unique identifier of this setInerval() method.

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!