Timer settimeout () and SetInterval () two are JS timer function of the function two some differences, the following for you to briefly introduce, I hope to help you
Timer settimeout () and SetInterval () two are all JS functions of the timing function two a little different. SetTimeout (): The explanation in the JS manual: To call a function or evaluate an expression after a specified number of milliseconds, that is, to execute after the set number of seconds is completed. Experimental code (change body background color): The code is as follows: settimeout (function () {$ ("body"). CSS ("Background", "Red"); },5000); SetInterval (): In the JS manual explains: Call a function or a calculation expression according to the specified period (in milliseconds). The function is called continuously until the Clearinterval () is called or the window is closed, and the number of seconds you set will execute your own effect code or function. Experimental code (a few seconds of experiment): The code is as follows: <div class= "Clock" ></div> <script> var num = 0; SetInterval (function () {$ (". Clock"). HTML (num++)},1000); </script> Summary: The settimeout () method executes the function after waiting for a specified time, and executes only one incoming handle function. The SetInterval () method executes an incoming handle function after each specified interval, looping until the window or clearinterval () is closed.