How could I do this? Refine search results as I type

岁酱吖の 提交于 2019-12-04 21:31:12

I made something like this a while ago. Here's a link.

What it does is fire this event on every key press, and matches the pressed key with a li that contains it. It works great, but could definitely use some modification. Here's the code:

$("#search").keyup(function(){
    $("li").hide();
   var term = $(this).val();
    $("li:contains('" + term + "')").show();
});

Basically, you have a JS (with jquery) code that performs json calls to retrieve a list of coincidences to the string already typed as it goes. It should show them in a div nearby the input field updating the innerHTML or something like that.

Below, a script/servlet/service that can be called every time with the input.

Example: http://woorkup.com/2010/09/13/how-to-create-your-own-instant-search/

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