Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

This question already has an answer here:

(这个问题在这里已有答案:)

What is the main difference between

(两者之间的主要区别是什么)

setInterval

(的setInterval)

and

(和)

setTimeout

(的setTimeout)

in JavaScript?

(在JavaScript?)

  ask by Pranay Rana translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
252 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...