<div >0</div>
    <button >click</button>
    <script>
        var oDiv = document.getElementById('show')
        var oBtn = document.getElementById('btn')

        function throttle(handler, wait) { // handler为函数  wait为时间
            var lastTime = 0
            return function() {
                var nowTime = new Date().getTime()  //获取时间
                if (nowTime - lastTime > wait) {  // 判断当前单击和上次单击的时间是否超过规定的时间
                    handler()
                    lastTime = nowTime   // 执行后将上次时间进行更新
                }
            }
        }

        function buy(e) { //需要执行的函数
            oDiv.innerText = parseInt(oDiv.innerText) + 1
        }
        oBtn.onclick = throttle(buy, 1000)
    </script>

 

相关文章:

  • 2021-08-17
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2021-05-03
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-07-04
  • 2021-08-14
  • 2022-12-23
相关资源
相似解决方案