代码:

/*
**防止多触发
*
*id 必须唯一
*fn 回掉函数
*wait 延迟多长时间
*
*使用例子:
* ToPreventMoreTrigger('id', function () {//注意 id 是唯一的
*           //响应事件
*          fun();
*       }, 500);
*
******/
var _timer = {};
function ToPreventMoreTrigger(id, fn, wait) {
    if (_timer[id]) {
        window.clearTimeout(_timer[id]);
        delete _timer[id];
    }

    return _timer[id] = window.setTimeout(function () {
        fn();
        delete _timer[id];
    }, wait);
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2021-12-23
  • 2021-06-30
  • 2021-12-01
  • 2021-12-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案