每个setTimeout()和setInterval()方法创建时产生了相对应的id,停止该方法就用到创建时产生的id
1.setTimeout()定时执行,setInterval()周期执行
function sayHello(){
console.log("Hello,你好!")
}
var timeOutId = setTimeout(sayHello,5000); //5秒后执行sayHello函数,只执行一次(定时)
var intervalId=setInterval(sayHello,5000); //每5秒执行一次sayHello函数,执行多次(周期)
2.clearTimeout()停止setTimeout()的执行,clearInterval()停止setIntervar()的执行
clearTimeout(timeOutId);
clearInterval(intervalId);