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

久未见 提交于 2019-12-22 01:13:47

问题


I've got a page with a bunch of thumbnails and titles:

http://thenozzle.net/games
(broken link)

If you hit "search", a search bar slides down from above. I can type things into the search box and hit enter to search the website. I was wondering if there was any way to look at all the thumbnails, and if I typed "E" it would hide all the thumbnails except for ones that started with "E". Then I typed "El" and it brought up every result that started with "El". Then I added a "d" and it would bring up every thumbnail with a title starting with "Eld". IN this, users could search the games page easily without having to reload. Is it possible? Worthwhile doing?

I've well-versed in jQuery and PHP. If my explanation didn't do it. Look into Google Instant.

Thanks!


回答1:


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();
});



回答2:


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/



来源:https://stackoverflow.com/questions/8192076/how-could-i-do-this-refine-search-results-as-i-type

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