<%@ page language= "java" contenttype= "Text/html; charset=utf-8" pageencoding= "Utf-8"%><! doctype html public "-//w3c//dtd html 4.01 transitional//en" "HTTP// Www.w3.org/TR/html4/loose.dtd ">Because the settimeout (expression, delay time) is executed, after the specified time is delayed after loading, the expression is executed once, remember, the number of times is
The setinterval (expression, interaction time) is not the same, it executes the expression once every specified time from loading
So, it's totally different.
Many people are accustomed to include settimeout in the executed function, and then use the settimeout again outside the function to achieve the purpose of timed execution, so that the settimeout outside the function triggers the settimeout again when the function is executed, resulting in a recurring timing effect.
When used, each has its own advantages, using the setinterval, you need to stop the tick trigger manually. The use of nested settimeout in the method, you can no longer call settimeout based on the internal logic of the method is equal to stop the trigger.
SetTimeout only runs once, that is, the set time is triggered to run the specified code, after the end of the run. If the same settimeout command is run again in the running code, it can be run in a loop.
The setinterval is loop-activated, that is, each time interval is set to trigger the specified code. This is the real timer.
SetInterval is simple to use, while settimeout is more flexible, can exit the loop at any time, and can be set to run at an irregular interval, such as the first 1 seconds, the second 2 seconds, the third time 3 seconds ...
Reference article:
http://heisetoufa.iteye.com/blog/269566
Http://www.cnblogs.com/mbtq/archive/2012/10/25/2740023.html
Http://blog.sina.com.cn/s/blog_921bd9650101db4b.html
This article is from the "Nothing-skywalker" blog, please be sure to keep this source http://tianxingzhe.blog.51cto.com/3390077/1681402
JS implementation snapping countdown accurate to milliseconds expiry prompt "snapping is over"