window.clearInterval与window.setInterval的用法
2013-11-20 19:59
260 查看
window.setInterval()
功能:按照指定的周期(以毫秒计)来调用函数或计算表达式。
语法:setInterval(code,millisec)
解释:code:在定时时间到时要执行的JavaScript代码串。
millisec:设定的定时时间,用毫秒数表示。
返回值:定时器的ID值,可用于clearInterval()方法停止指定的定时器。
注:setInterval()方法会不停地调用函数,直到用clearInterval()终止定时或窗口被关闭。
window.clearInterval()
功能:取消由setInterval()方法设置的定时器。
语法:clearInterval(id_of_setinterval)
解释:id_of_setinterval:由setInterval()返回的ID值。该值标识了一个setInterval定时器。
也就是:window.setInterval()返回的就是window.clearInterval的参数
例子:
View Code
再如:
var objTimer = window.setInterval("moveDiv()",10)是调动定时器,其中moveDiv是js的一个函数
if(objTimer) window.clearInterval(objTimer)是停止定时器
功能:按照指定的周期(以毫秒计)来调用函数或计算表达式。
语法:setInterval(code,millisec)
解释:code:在定时时间到时要执行的JavaScript代码串。
millisec:设定的定时时间,用毫秒数表示。
返回值:定时器的ID值,可用于clearInterval()方法停止指定的定时器。
注:setInterval()方法会不停地调用函数,直到用clearInterval()终止定时或窗口被关闭。
window.clearInterval()
功能:取消由setInterval()方法设置的定时器。
语法:clearInterval(id_of_setinterval)
解释:id_of_setinterval:由setInterval()返回的ID值。该值标识了一个setInterval定时器。
也就是:window.setInterval()返回的就是window.clearInterval的参数
例子:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>test</title> </head> <body> <input type="button" value="开始计时" onclick="beginCount()" /> <input type="text" id="timetxt" size="5" /> <input type="button" value="停止计时" onclick="stopCount()" /> <script type="text/javascript"> var count = 0; var timeID; function timeCount() { document.getElementById('timetxt').value = count; count++; } function beginCount() { timeID = setInterval("timeCount()",100); } function stopCount() { clearInterval(timeID); } </script> </body> </html>
View Code
再如:
var objTimer = window.setInterval("moveDiv()",10)是调动定时器,其中moveDiv是js的一个函数
if(objTimer) window.clearInterval(objTimer)是停止定时器
相关文章推荐
- window.clearInterval与window.setInterval的用法(
- window.setInterval()方法的定义和用法及offsetLeft与style.left的区别
- window.setInterval的用法.
- setInterval 和 clearInterval的用法
- setInterval 、 settimeout 、clearInterval 用法(特殊情况下代替schedule)
- window.setInterval()方法的定义和用法及offsetLeft与style.left的区别
- window.clearInterval()方法和window.setInterval()方法
- 关于时间间隔函数setinterval的用法
- window.setInterval()什么意思
- JavaScript window.setTimeout() 的详细用法
- JavaScript window.setTimeout() 的详细用法
- window.setInterval
- JS setInterval()、 setInterval()与 clearInterval() 方法的使用
- JavaScript window.setTimeout() 的详细用法
- 停止window.setInterval("fs()",1000)
- JavaScript window.setTimeout() 的详细用法
- JavaScript window.setTimeout() 的详细用法
- setInterval&&clearInterval
- JavaScript window.setTimeout() 的详细用法
- Js_window.setInterval & window.setTimeout