Instant search function in Javascript

匆匆过客 提交于 2019-12-01 11:19:10
function instantSearch(){ ... }

var timer;
$('input').keyup(function(){
   timer && clearTimeout(timer);
   timer = setTimeout(instantSearch, 200);
});

Is your instant search function making an AJAX request to return results? That might be the difference between setting the delay to 200ms and getting your response back 1-2s later.

If you're using the keyup event it shouldn't be necessary to specify a delay unless there are specific limits on queries-per-second or something similar.

There's a fairly concise walkthrough here: http://blog.comperiosearch.com/2012/06/make-an-instant-search-application-using-json-ajax-and-jquery/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!