Home >Web Front-end >JS Tutorial >JavaScript scheduled function call

JavaScript scheduled function call

高洛峰
高洛峰Original
2016-11-25 14:59:551154browse

setTimeout("test()",1000): Execute once after a given time
setInterval("test()",1000): Execute once after a given time
The time unit is milliseconds
setTimeout can also be used to implement Repeatedly execute after a fixed period of time:
function test(){
//Your logic processing
setTimeout("test()",1000);
}
The difference between these two methods is:
setTimeout must be executed Your logic will be executed after a fixed time. It is a single process and will not affect the public data.
setInterval is executed once every fixed time, regardless of whether the previous method has been completed. It is a multi-process. There may be errors when modifying shared data

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:js millisecond countdownNext article:js millisecond countdown