let btnName = document.getElementById("btn");
btnName.onclick = throttle(function () {
console.log(1);
}, 2000);
function throttle(fn,wait) {
let timer;
return function (...args) {
if (timer) return;
timer = setTimeout(() => (timer = null), wait);
return fn(args);
};
}
网友评论