防抖

24 阅读1分钟
     var btn = document.getElementsByTagName('input')[0];
        function paymoney() {
            console.log(111111);
        };
        function debounce(func, wait) {
            let timer;
            return function () {
                clearTimeout(timer);
                let context = this;
                timer = setTimeout(function () {
                    func.call(context);
                }, wait)
            }
        }
        btn.addEventListener('click', debounce(paymoney, 500));
   <input type="button" style="width:100px;height:100px;" value="剁手">