您的位置 首页 技术

JS 中 setTimeout 和 setInterval 区别

JS中 setTimeout 和 setInterval 区别 setTimeout方法的作用是在指定的毫秒数后执行函数或表达式,而setInterval方法则是在每隔指定的毫秒数…

JS中 setTimeout 和 setInterval 区别

setTimeout方法的作用是在指定的毫秒数后执行函数或表达式,而setInterval方法则是在每隔指定的毫秒数循环执行函数或表达式,直到clearInterval方法将其清除。

代码区别

setTimeout

function hello(){alert("hello");}//使用方法名字执行方法var t1 = window.setTimeout(hello,1000);var t2 = window.setTimeout("hello()",3000);//使用字符串执行方法window.clearTimeout(t1);//清除定时器

setInterval

//实时刷新时间单位为毫秒setInterval('refreshQuery()',8000); /* 刷新查询 */function refreshQuery(){   $("#mainTable").datagrid('reload',null);}

推荐教程:《JS教程》

以上就是JS 中 setTimeout 和 setInterval 区别的详细内容,更多请关注24课堂在线网其它相关文章!

本文来自网络,不代表24小时课堂在线立场,转载请注明出处:https://www.24ketang.cn/65745.html

为您推荐

返回顶部