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 区别的详细内容。