/* 过3秒钟 把这个广告显示出来 */ document.getElementById('guangao').style.display = 'block' setTimeout(function () { document.getElementById('guangao').style.display = 'none' }, 3000)
/* 过个一段时间去做一件事 */
/* 定时器 */
/* 定时器会返回一个唯一的id */
let id = setInterval(function(){
console.log('我爱js<br>');
console.log(id);
},1000)
// /* 根据定时器返回的唯一的id 来清除定时器 */
/* function clearfn() {
clearInterval(id)
} */
/* 过一秒钟 在控制台上打印出 一个数字 比如1
再过一秒钟 打印出2 ....
点击清除定时器 终止打印 */
let i = 0;
let id = setInterval(function () {
i++;
console.log(i);
}, 1000)
function clearfn() {
clearInterval(id)
}
/* setTimeout 和 setInterval的区别是
setTimeout只执行一次
也会产生一个唯一的id标识 */
/* let id = setTimeout(function (){
console.log('我说冷笑话');
},1000) */