搜索建议缓存 javascript

发布于 2024-10-20 02:21:40 字数 346 浏览 8 评论 0原文

我有一个搜索文本框,我必须为其实现搜索建议(如谷歌搜索)之类的功能。

例如,如果我在搜索框中输入“abc”,我会得到类似的建议
abcdef
xyzabcxyz

这里每个独特的建议都代表一个 jsp 页面,其 url 可以“硬编码”在 java 脚本数组中。因此,当我单击任何建议值时,都会显示相应链接的网页。

为此,您能否建议我任何有效的方法来实现这一点。
这必须是纯javascript,不能使用jquery等第三方库

提前感谢。

I am having a Search text-box for which I have to implement a search suggestion(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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧夏天 2024-10-27 02:21:40

假设您的数据位于与此类似的 关联 JS 数组

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

,并且您的搜索输入字段有与 onkeyup 关联的函数

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

,那么剩下的就是简单的 JavaScript 字符串函数

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文