实现节流函数
<button id='show'>抢购</button>
<div id="box">0</div>
let oBtn=document.getElementById('show');
let oBox=document.getElementById('box');
//在规定的时间可以触发事件
function throttle (handle, wait) {
let lastTime = 0;
return function (e) {
let nowTime = new Date().getTime()
if (nowTime - lastTime > wait) {
handle();
lastTime = nowTime;
}
}
}
function buy(){
oBox.innerText = parseInt(oBox.innerText)+1
}
oBtn.onclick = throttle(buy, 2000)