您的位置:首页 > Web前端 > JavaScript

js定时器SetInterval与setTimeout

2015-07-02 12:49 686 查看
SetInterval为自动重复,setTimeout不会重复。

setTimeout("function",time) 设置一个超时对象 

setInterval("function",time) 设置一个超时对象

clearTimeout(对象) 清除已设置的setTimeout对象
clearInterval(对象) 清除已设置的setInterval对象

function hello(){      

alert("hello");

}

var id=window.setTimeout(hello,5000);

document.onclick=function(){     

window.clearTimeout(id);

 }

SetInterval类似。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: