This question already has an answer here:
(这个问题在这里已有答案:)
- setTimeout or setInterval? 17 answers
(17个答案)
What is the main difference between
(两者之间的主要区别是什么)
and
(和)
in JavaScript?
(在JavaScript?)
ask by Pranay Rana translate from soThis question already has an answer here:
(这个问题在这里已有答案:)
(17个答案)
What is the main difference between
(两者之间的主要区别是什么)
and
(和)
in JavaScript?
(在JavaScript?)
ask by Pranay Rana translate from so setTimeout(expression, timeout);
runs the code/function once after the timeout.
(超时后运行代码/函数一次。)
setInterval(expression, timeout);
runs the code/function in intervals, with the length of the timeout between them.
(以间隔运行代码/函数,以及它们之间的超时长度。)
Example:
(例:)
var intervalID = setInterval(alert, 1000); // Will alert every second.
// clearInterval(intervalID); // Will clear the timer.
setTimeout(alert, 1000); // Will alert once, after a second.