码迷,mamicode.com
首页 > 编程语言 > 详细

Javascript定时器的开启与关闭简单使用

时间:2015-08-20 22:42:12      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html>
<head>
<title>this is test page</title>
<script type="text/javascript">
    window.onload=function(){
    var oBtn1=document.getElementById(‘btn1‘);
    var oBtn2=document.getElementById(‘btn2‘);
    var timer=null;
        oBtn1.onclick=function(){
        timer=setInterval(function(){
          alert(‘hello,world‘);
        },1000);                                          //每隔一秒执行弹出操作
        };
        oBtn2.onclick=function(){
        clearInterval(timer);                   //关闭定时器
        };
    };
</script>
</head>
<body>
<input id="btn1" type="button" value="open" />
<input id="btn2" type="button" value="close" />
</body>
</html>

Javascript定时器的开启与关闭简单使用

标签:

原文地址:http://my.oschina.net/dongdong11019/blog/495274

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!