使用 jQuery 'on'函数将事件传递给 _.throttle 函数



我该如何将事件传递给_。节流功能。我需要传递触发这个函数的元素的id。下面是代码示例:

function aaa (id) {
  console.log(id);
}

jQuery('#inputStreet').on('input', _.throttle(aaa(event.target.id), 2000));

控制台提示无法读取未定义属性'target'

您需要传递给_.throttle一个函数,而不是函数调用的结果

jQuery('#inputStreet').on('input', _.throttle(function(event){
    aaa(event.target.id);
}, 2000));

最新更新