Home > Web Front-end > JS Tutorial > Definition and usage of js clearInterval() method_javascript skills

Definition and usage of js clearInterval() method_javascript skills

WBOY
Release: 2016-05-16 15:32:52
Original
1319 people have browsed it

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.

Grammar structure:

clearInterval(id)

Parameter list:

参数 描述
id 必需。此id是setInerval()的返回值,是此setInerval()方法的唯一标识。

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;
}
#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>
Copy after login

Click the button with the above code to cancel the digital auto-increment effect.

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