js中有两种定时器,setTimeout()和setInterval()
这两种定时器的区别在于 setTimeout()是一次性的定时器
而setInterval()是循环的定时器。
以下是两种定时器的写法:
1. setTimeout():
setTimeout(function(){
console.log("hello")},1000
)//倒计时一秒后执行function中的语句
2. setInterval():
setInterval(
function(){
console.log("hello")},1000
)//每隔一秒调用一次