一、setInteval()
This timer method has two parameters. The first parameter is the function, which is the function code that needs to be executed. The second parameter is the time value, which is how long to execute a function. The unit is milliseconds.setInteval(function(){},time)
(1) Demand: pop up 1 every two seconds
function a(){
alert('1');
}
setInteval(a,2000);
(2) Cancel the timing function
The value returned by setInteval() is the timer ID, and we can cancel the timer by passing this ID value to the parameter of clearInterval().
二、setTimeout()
Simply speaking, it is different from setInteval(). The parameters of setTimeout() are also functions and time, but they are executed only once. Use the ID value returned by setTimeout() to pass to clearTimeout() to cancel execution