搜索建议缓存 javascript
我有一个搜索文本框,我必须为其实现搜索建议(如谷歌搜索)之类的功能。
例如,如果我在搜索框中输入“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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您的数据位于与此类似的 关联 JS 数组 中
,并且您的搜索输入字段有与
onkeyup
关联的函数,那么剩下的就是简单的 JavaScript 字符串函数 。
Assuming your data is in an associative JS array similar to this
and your search input field has a function associated to
onkeyup
then the rest is simple JavaScript string functions.