📜  js 停止输入事件 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:17.791000             🧑  作者: Mango

代码示例1
function debounce(callback, wait) {
  let timeout;
  return (...args) => {
      clearTimeout(timeout);
      timeout = setTimeout(function () { callback.apply(this, args); }, wait);
  };
}

window.addEventListener('keyup', debounce( () => {
    // code you would like to run 1000ms after the keyup event has stopped firing
    // further keyup events reset the timer, as expected
}, 1000))