你可以通过你自己写去抖方法:
var timer = null;
searchInput.addEventListener('keyup', function (evt) {
clearTimeout(timer);
timer = setTimeout(function() {
// this event listener will postpone its execution until after 1 second have elapsed since the last time it was invoked
// send your ajax request here
}, 1000);
}, false);
或者您可以使用underscore限制keyup事件:
searchInput.addEventListener('keyup', _.debounce(function (evt) {
// this event listener will postpone its execution until after 1 second have elapsed since the last time it was invoked
}, 1000), false);
请不要把两个不相干的查询,在一个问题。 – Alnitak 2012-04-27 13:46:58
[等待函数直到用户停止输入]的可能的重复(http://stackoverflow.com/questions/10124114/wait-for-function-till-user-stops-typing) – Alnitak 2012-04-27 13:47:52