jQuery 自动完成显示焦点上的所有选项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1464796/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
autocomplete show all options on focus
提问by krishna
Iam using this plugin.
我正在使用这个插件。
How do I show all the options available in the dropdown for an input field when it receives focus? Right now , I have to type something for the plugin to filter the options.
当输入字段获得焦点时,如何在下拉列表中显示它的所有可用选项?现在,我必须为插件输入一些内容来过滤选项。
What I have right now
我现在拥有的
var $sessionTimes = "00:00 00:15 00:30 00:45 1:00 1:15".split(" ");
$(".autocompleteTime").autocomplete($sessionTimes);
<input type="text" class="autocompleteTime" size="5" />
回答by inkredibl
You have to set minChars to be 0, like this:
您必须将 minChars 设置为 0,如下所示:
$('.autocompleteTime').autocomplete($sessionTimes, {minChars: 0});
Also note that you don't have to start variable name with a $, you could just write sessionTimes everywhere you use it and it would be okay. Probably coming from a PHP background? :)
另请注意,您不必以 $ 开头变量名,您可以在任何使用它的地方编写 sessionTimes 就可以了。可能来自 PHP 背景?:)
回答by RayLoveless
This is the correct answer:
这是正确答案:
$('.autocompleteTime').autocomplete($sessionTimes, {minChars: 0})
.focus(function () {
$(this).autocomplete('search', $(this).val())
});
回答by Ahmed-Anas
The selected answer is a bit old and didn't really work for me, so what worked for me was this:
选择的答案有点旧,对我来说并没有真正起作用,所以对我有用的是:
$('#selector')
//use minLength when initializing so that empty searches work
.autocomplete({..., minLength: 0})
//trigger the search on focus
.focus(function(){
$(this).autocomplete('search', $(this).val());
})
Credits to the comment by @notJim above and this question: Display jquery ui auto-complete list on focus event, and to me
感谢@notJim 上面的评论和这个问题:Display jquery ui auto-complete list on focus event,以及我
回答by mynameistechno
Check out jQuery Ui's Autocomplete combobox example:
查看 jQuery Ui 的自动完成组合框示例:
回答by jerrygarciuh
That module has now been incorporated into the jQuery UI. This post covers how to deal with this problem now:
该模块现已合并到 jQuery UI 中。这篇文章介绍了现在如何处理这个问题: