<!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>原文:http://my.oschina.net/dongdong11019/blog/495274