开发者

Search suggestion cache javascript

开发者 https://www.devze.com 2023-02-14 07:54 出处:网络
I am having a Search text-box for which I have to implement a search sugge开发者_JAVA百科stion(like google search) kind of feature.

I am having a Search text-box for which I have to implement a search sugge开发者_JAVA百科stion(like google search) kind of feature.

for example, if I type "abc" in the search box, I will get suggestions like

abcdef

xyzabcxyz

here each of these unique suggestion represents a jsp page whose url can be "hard-coded" in a java-script array. so when I click any suggested value, the webpage at the corresponding link is displayed.

For this, can you suggest me any efficient methods of implementing this.

This must be in pure javascript, no third-party libs like jquery,etc., can be used

Thanks in advance.


Assuming your data is in an associative JS array similar to this

var locationArray = {
    'searchValue1' : 'url1',
    'searchValue2' : 'url2',
        ...
};

and your search input field has a function associated to onkeyup

<input type="text" onkeyup="UpdateSuggestions(this);">

then the rest is simple JavaScript string functions.

0

精彩评论

暂无评论...
验证码 换一张
取 消