Ajax 自动完成(或自动建议)与 TAB 完成/自动填充类似于 shell 命令行完成?
我正在实现 AJAX 自动完成/自动建议功能,我不仅想要执行与用户键入的内容类似的通常显示建议,而且还想让用户完成部分完成以节省键入。
所以,想象我的字典中有这些值:“青苹果”,“青梨”,“绿色水果”,“蓝天”,“蓝色水”,“蓝色唤醒”。
如果用户输入“g”,建议应该是“青苹果”,“青梨”,“绿色水果”,我想让用户点击TAB或其他东西来将他的查询更新为“绿色”,然后他们可以输入“a”,然后他们就会完成“青苹果”。
我正在尝试在 linux shell 命令行完成后对此进行建模。
您能推荐一个可以执行此操作的控件/脚本吗?或者对现有控件进行修改/定制?
I'm implementing a AJAX autocomplete/autosuggest feature, and not only do I want to do the usual show suggestions that are similar to what the user typed, but I'd like to let the user do partial completions to save typing.
So, imagine my dictionary has these values in it: "green apple", "green pear", "green fruit", "blue sky", "blue water", "blue wake".
If the user types in "g", the suggestions should be "green apple", "green pear", "green fruit", and I'd like to let the user hit TAB or something to update his query to "green ", then they could type "a" and they'd get completed to "green apple".
I'm trying to model this after linux shell command line completion.
Can you recommend a control/script that does this? Or a modification/customization of an existing control?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
流行的自动完成插件(例如 jQuery、Scripty...)不支持这种特定类型的自动完成,因为这些插件通常提供一个下拉 UI 来选择所需的匹配。
因此,假设我们还没有现成的解决方案。嘘嘘。编写代码有多难?
测试页面 - 它应该可以在普通浏览器中工作。为了支持 IE,请使用来自prototype.js、jQuery 或其他的事件监听。
This specific type of autocompletion isn't supported in popular autocompletion plugins (for jQuery, Scripty...) because usually those provide a drop-down UI for choosing the wanted match.
So let's suppose we haven't got an out-of-the-box solution. Boo-ho. How hard can it be to code it up?
Test page here — it should work in normal browsers. For supporting IE use event listening from prototype.js, jQuery or other.
如果您使用 jQuery,一个很棒的插件是 http://bassistance.de/jquery-插件/jquery-plugin-autocomplete/。
只需使用 css 隐藏下拉框,并保留选项卡自动完成功能即可。
我认为为自己制作一个 jquery 插件会很简单......
沿着以下路线
监听 Tab 键
当按下 tab 键时,在 input.autotab 上触发 tab:press
将 input.autotab 的 tab:press 事件(在每个循环中...如果 focus==true 等)绑定到 javascript 数组查找或 xhr 请求,(ajax),然后将该输入的值设置为返回的数据。
在自动建议脚本中,一旦该值在数据库中匹配多次(使用带有索引的 for 循环,在第一个元素匹配的索引元素处停止),就将其写入,并返回到该点的值。
If your using jQuery, a great plugin is http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/.
Simply use css to hide the dropdown box, and leave the tab-auto-complete functionality on.
I think it would be simple to make a jquery plugin for yourself...
Along the lines of
Listen for the Tab Key
When the tab key is pressed, trigger tab:press on input.autotab
Bind input.autotab's tab:press event (in an each loop... if focus==true etc.) to either a javascript array lookup, or a xhr request, (ajax), then set that input's value as the returned data.
In your autosuggest script, write it so once the value is matched more than once in the database (use a for loop with an index, stopping at the index element where the first element is matched), and return the value up to that point.
最简单的方法是使用 jQuery 和自动完成插件。查看 stackoverflow html,似乎他们使用的是相同的东西。似乎对于大多数浏览器来说都工作得很好。该插件还有一个广泛的演示,可以帮助您了解如何根据您的特定需求实现它。
以下是插件主页的快速示例:
更多内容可在此处找到 http://docs.jquery.com /插件/自动完成
The simplest way would be to just use the jQuery and the autocomplete plugin. Looking the the stackoverflow html, it seems that they are using the same stuff. Seems to work very well for most browsers. The plugin also has an extensive demo that should help you figure out how to implement it to your specific needs.
Here's a quick sample from the plugin home page:
More to be found here http://docs.jquery.com/Plugins/Autocomplete