js中的setInterval,setTimeout的使用

1,Window  setInterval(),clearInterval方法

setInterval()方法会不停地调用函数,知道clearInterval()被调用,或窗口被关闭

var timer = null;
timer = setInterval('函数','毫秒') 
 clearInterval(timer) ; //清除定时器
//利用setInterval,实现循环
<script> var i=0; function fn1(){ document.title = i; i++; if(i==10){ clearInterval(timer); } } var timer = null ; timer = setInterval(fn1,200) </script>

 

2,setTimeout,clearTimeout

setTimeout(‘函数’,毫秒) ;用于在指定的毫秒后执行一次,(只执行一次!)。

posted @ 2017-07-27 09:26  千寻的天空之城  阅读(204)  评论(0编辑  收藏  举报