如何做像 Google/Wiki/Facebook 搜索字段这样的东西?
他们的搜索字段可以输入并在此处显示某种列表......例如,当我输入“Wikipedia”时,当我开始输入“W”时,它有“Wi”,“Wii”,“Will”,类似的事情... ...如何做类似的事情?谢谢。
Their search fields can type and have some kind of list is showing here.... For example, when I type "Wikipedia" , when I start type "W", it have "Wi", "Wii", "Will" , somethings like that... ...How to do something similar like this? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有几个 JavaScript 库提供了此功能。例如,对于 jQuery,您可以使用 Autocomplete pulgin。该链接还包含一个演示。
Several javascript libraries provide this functionality. For example with jQuery, you can use the Autocomplete pulgin. The link also includes a demo.
根据您计划如何使用自动完成功能,有一个 jquery 插件可以帮助您实现此功能。
本质上,您是在用户键入时捕获数据,并检查某种类型的数组以查看类似的匹配项。您的数组可以静态设置,也可以使用 ajax 动态设置,以查询返回类似数据的脚本。
看:
http://code.drewwilson.com/entry/autosuggest-jquery-plugin
Depending on how you are planning on using the auto complete there is a jquery plugin that can help with this feature.
Essentially you are capturing the data as a user types and are checking against an array of some type to see similar matches. Your array can be statically set or be dynamic using ajax to query a script which returns data that is similar.
See:
http://code.drewwilson.com/entry/autosuggest-jquery-plugin
jQuery liveSearch 插件可以做到这一点。这是插件站点,其中包含连接 php 搜索页面的详细说明: http://andreaslagerkvist.com /jquery/live-search/
the jQuery liveSearch plugin will do this. Here is the plugin site with pretty detailed instructions for connection to a php search page: http://andreaslagerkvist.com/jquery/live-search/