定时器分为两种:setTimeout(一次性),setInterval(周期性)
setTimeout:setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式。
使用:setTimeout(function(){ 被执行方法或内容); }, 毫秒时间);
实例:
setTimeout(function () {
console.log("hello world");
},3000)

clearTimeout: clearTimeout() 方法可取消由 setTimeout() 方法设置的 timeout。
使用: clearTimeout(定时器名称);
实例:
let to = setTimeout(function () {
console.log("hello world");
}, 3000);
clearTimeout(to);

setInterva:setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式。
使用:setInterval(function(){ 被执行方法或内容); }, 毫秒时间);
实例:
setInterval(function () {
console.log("hello world");
},300)

clearInterval: clearInterval() 方法可取消由 setInterval() 设置的 timeout。
使用: clearInterval(定时器名称);
实例:
let Tv= setInterval(function () {
console.log("hello world");
},300)
clearInterval(Tv);
