节流 // 指定事件内直触发一次事件 var app = document.getElementById("app") function addone() { console.log("我是结束后出现的内容") } function shake(func,times) { let time; return function () { if (!time) { time = setInterval(function () { func() clearInterval(time) time = null }, times) } else { console.log("已经有定时器了",2000) } } } app.addEventListener("click", shake(addone)) 防抖 //多次点击时只触发最后一次 var app = document.getElementById("app") function addone() { console.log("我是结束后出现的内容") } function shake(func) { let time; return function () { clearInterval(time) time = setInterval(function () { func() }, 1000) } } app.addEventListener("click", shake(addone))