js定时器setInterval、setTimeout的使用
2014-01-11 09:41
477 查看
js定时器的使用,
开启定时器setInterval(间隔型)、setTimeout(延时型);
关闭定时器clearInterval、clearTimeout;
定时器使用小案例:
开启定时器setInterval(间隔型)、setTimeout(延时型);
关闭定时器clearInterval、clearTimeout;
定时器使用小案例:
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>五指前端</title> <style type="text/css"> #div1{width:200px; height:100px; background-color:#ccc;} </style> <script type="text/javascript"> function show() { alert('定时器开启了'); } window.onload=function() { var oBtn1=document.getElementById('btn1'); var oBtn2=document.getElementById('btn2'); var timer=null; //声明一个时间变量 oBtn1.onclick=function() { timer=setInterval(show,2000); //开启定时器 间隔2秒执行show函数 同时赋给之前声明好的时间变量timer } oBtn2.onclick=function() { clearInterval(timer); //关闭定时器timer } } </script> </head> <body> <input type="button" id="btn1" value="开启定时器" /><input type="button" id="btn2" value="关闭定时器" /> </body> </html>
相关文章推荐
- js中 setTimeout和setInterval的使用
- setTimeout和setInterval的使用
- Jquery中使用setInterval和setTimeout的方法
- JavaScript SetInterval与setTimeout使用方法详解
- Jquery中使用setInterval和setTimeout
- Jquery中使用setInterval和setTimeout 实现定时执行函数
- javascript 中的 setTimeout和setInterval的使用
- js中的setInterval和setTimeout使用实例
- setTimeout和setInterval的使用说明
- setInterval和setTimeout的使用区别
- Jquery中使用setInterval和setTimeout会提示缺少对象的错误,解决方法如下:
- Jquery中使用setInterval和setTimeout
- [HTML]js定时器使用 setInterval
- 如何使用定时器settimeout、setInterval执行能传递参数的函数(转)
- setTimeout和setInterval的使用
- js学习--浏览器对象计时器setInterval()与setTimeout()的使用与区别
- JS中SetTimeout和SetInterval使用初探
- 如何使用定时器settimeout、setInterval执行能传递参数的函数
- 如何在jQuery中使用 setInterval,setTimeout
- setTimeout和setInterval的使用