Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

javascript - 'setInterval'vs'setTimeout'[复制]('setInterval' vs 'setTimeout' [duplicate])

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

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

1 Reply

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...