Timers setTimeout() and setInterval() are both js timing functions. There are some differences between them.
setTimeout():
Explanation in the js manual: Used to call a function or calculate an expression after a specified number of milliseconds;
That is to say, after execution Execute after the set number of seconds.
Experimental code (change body background color):
setTimeout(function(){
$("body").css("background","red");
},5000);
setInterval() :
Explanation in the js manual: Call a function or calculate an expression according to the specified period (in milliseconds). The function will be called continuously until clearInterval() is called or the window is closed;
Execute your own effect code or function within the number of seconds you set.
Experimental code (several seconds experiment):
<script> <br>var num = 0; <br>setInterval(function(){$(".clock").html( num )},1000); <br></script>
Summary:
The setTimeout() method executes the function after waiting for the specified time, and only executes the transfer once The incoming handle function. The
setInterval() method executes the incoming handle function after every specified interval, and executes in a loop until the window is closed or clearInterval().