Javascript jQuery 自动完成 minLength
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4265523/
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
jQuery autocomplete minLength
提问by Robin Maben
The autocomplete never fires on first character entered but 2nd. Although after using back-space it works for the minLength = 1. Also, the selectFirst:truenever defaults to first item in the array on page load.
自动完成永远不会在输入的第一个字符上触发,而是在第二个字符上触发。虽然在使用退格后它适用于minLength = 1。此外,selectFirst:true永远不会默认为页面加载时数组中的第一项。
$().ready(function (){
$('#CompanyName').autocomplete({
source: companyNames,
select: SetLocations,
selectFirst :true,
minLength: 0 //corrected as suggested, but still no change
});
});
Has anybody faced this behavior before. I'm clueless since I haven't any global settings/defaults.
有没有人遇到过这种行为。我一无所知,因为我没有任何全局设置/默认值。
回答by Nick Craver
You have a few syntactical errors, the document.ready
handler is missing a brace (and is deprecated anyway) and a comma in your options, it should look like this:
您有一些语法错误,document.ready
处理程序缺少大括号(无论如何都已弃用)和选项中的逗号,它应该如下所示:
$(function() {
$('#CompanyName').autocomplete({
source: companyNames,
select: SetLocations,
selectFirst: true, //here
minLength: 0
});
});
Also, autocomplete activates afterminLength
characters, if you want it immediately, use 0
, from the docs:
此外,自动完成在minLength
字符后激活,如果您想要立即使用0
,请使用, from the docs:
minLength: The minimum number of characters a user has to type before the Autocomplete activates. Zero is useful for local data with just a few items. Should be increased when there are a lot of items, where a single character would match a few thousand items.
minLength:在自动完成激活之前用户必须键入的最小字符数。零对于只有几个项目的本地数据很有用。当有很多项目时应该增加,其中单个字符将匹配几千个项目。
.....
.....