js---定时器
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
//window 对象是一个最顶层对象
//window.setInterval("alert('123');",2000);//每个两秒弹出一次消息框
function test(){
console.log("setINterval 调用了");
}
setInterval("test()",2000);
//如上实现一个函数的循环调用
//setTimeout("test()",2000);//2000ms执行一次之后就不在执行。不具备setInterval的循环功能。
var timerID;
function start()
{
timerID=setInterval("test()",2000);
}
function stop()
{
clearInterval(timerID);//使用语法停止了计时器的运行
}
</script>
</head>
<body>
<input type="button" value="开启定时器" onclick="start()" />
<input type="button" value="停止定时器" onclick="stop()" />
</body>
</html>
转载于//www.cnblogs.com/byczyz/p/11201030.html
还没有评论,来说两句吧...