找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 js教程 查看内容

JS 中 setTimeout 和 setInterval 区别

作者:模板之家 2020-5-29 13:24 5421人关注

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

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);
}

路过

雷人

握手

鲜花

鸡蛋
原作者: php中文网 来自: php中文网

全部回复(0)