jQuery的谷歌类型建议与限制到列表 [英] jquery Google type suggest with restrict to list
问题描述
我目前在页面上具有一些功能,可以根据用户在文本框中键入的内容向用户提供建议(jquery建议).我要添加的功能是将选择/输入到文本框中的内容限制为仅是列表中的项目.基本上就像一个组合框,将其选择限制在列表中.
I currently have functionality on a page to give a user suggestions based on what they type in a text box (jquery suggest). The functionality I would like to add is to restrict what gets selected / entered into the text box to only be items in the list. Basically like a combobox which restricts its selections to what's in the list.
我想到的一个方法是验证文本框中的条目是否与列表中的项目匹配.我必须提醒用户输入的内容是不允许的(或者也许有一种方法可以让他们输入其他字符?),可以,但不是真正干净的ui.
One thought I had is to verify that the entry in the textbox matches to an item in the list. I would have to alert the user that what is entered isn't allowed (or maybe there is a way to keep them typing other characters?), it's OK, but not real clean ui.
我认为某人在SO上做了这样的事情;如果有人有想法实现此功能,请告诉我.
I figure someone on SO has done something like this; if someone has an idea to achieve this functionality please let me know.
我使用的基本jquery:
The basic jquery I used:
<script type="text/javascript">
$(function() {
$('#autocomplete').autocomplete("getPcodes.aspx", { mustMatch: true, autoFill:true, multipleSeparator: "; ", minChars:3 });
});
</script>
自动完成功能有很多不错的选择.我以前使用过一个建议性的jquery,但是我想我会选择使用它.
There are a lot of nice options with the autocomplete. I was using a suggest jquery before, but I think I will opt for this one instead.
推荐答案
jQuery自动完成插件可让您强制用户从返回的数据集中选择一个选项.
The jQuery Autocomplete plugin lets you force the user to select an option from the returned dataset.
检查选项必须匹配 http://docs.jquery.com/Plugins/Autocomplete /autocomplete#url_or_dataoptions :
如果设置为true,则自动完成程序将仅允许后端显示的结果.请注意,非法值会导致输入框为空.
If set to true, the autocompleter will only allow results that are presented by the backend. Note that illegal values result in an empty input box.
这篇关于jQuery的谷歌类型建议与限制到列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!