setTimeout 与setInterval 用法案例

来源:互联网 发布:linux 进程执行了sleep 编辑:程序博客网 时间:2024/04/28 22:23

setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式。(设置一个超时对象,只执行一次,无周期)

案例:

setTimeout( function(){$( '#div_register_res' ).fadeOut();
window.location.href="enterpriseuser.html";
}, ( 1 * 1000 ) );

1秒后执行函数隐藏提示层,跳转到下一个页面

setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式。(设置一个超时对象,周期='交互时间')

案例:

 一旦调用了这个函数PerReflesh,那么就会每隔5秒钟就显示一次时间

var clock = setInterval("PerRefresh()", 5000);

function PerRefresh() {
     var today = new Date();
     alert("The time is: " + today.toString());
}


clearInterval(clock); //清除js定时器

原创粉丝点击