‘setInterval’vs‘setTimeout’.‘>之间的主要区别是什么?SET Interval和SETTimeout用JavaScript?
3 回答
回首忆惘然
TA贡献1847条经验 获得超11个赞
setTimeout(expression, timeout);
setInterval(expression, timeout);
var intervalID = setInterval(alert, 1000); // Will alert every second.// clearInterval(intervalID); // Will clear the timer.setTimeout(alert, 1000); // Will alert once, after a second.
www说
TA贡献1775条经验 获得超8个赞
setTimeout():
AFTER
setTimeout(function () { something();}, 1000); // Execute something() 1 second later.
setInterval():
EVERY
setInterval(function () { somethingElse();}, 2000); // Execute somethingElse() every 2 seconds.
millisecond
添加回答
举报
0/150
提交
取消