一、定时器的使用 开启定时器,每隔3秒钟打印,打印3次hello后,清除定时器 //定义次数的变量 let repeat=0; let timer=setInterval( function(){ repeat++; console.log('hello!'); if(repeat>=3){ clearInterval(timer); } },3000)