| 方法 | 说明 |
| setInterval() | 按照指定的周期,(以毫秒为单位)来调用函数或计算表达式 循环执行 |
| setTimeout() | 在指定的毫秒数后调用函数或计算表达式 执行一次 |
| clearInterval() | 取消由setInterval()方法生成的定时器对象 |
| clearsetTimeout() | 取消由setTimeout()方法生成的定时器对象 |
var p=document.getElementsByTagName("p")[0]; p.onclick=function(){ var b=setTimeout(function(){ alert(p.style.color="red"); },5000); clearTimeout(b); //清除timeout延迟 }
var p=document.getElementsByTagName("p")[0];
var out=setInterval(f,1000);
var i=0;
function f(){
p.innerText=i++;
if(i>10){
clearInterval(out);
alert("10秒钟已经到了");
}
}
原文:https://www.cnblogs.com/xiaowie/p/10593624.html