如何在 jQuery UI 自动完成中设置至少两个字符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11106395/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 10:11:34  来源:igfitidea点击:

How to set at least two characters in jQuery UI autocomplete?

jqueryjquery-ui

提问by Derfder

I am using jQuery autocomplete and would like to limit the showing results only when the user types at least 2 characters. How to do that?

我正在使用 jQuery 自动完成功能,并希望仅在用户键入至少 2 个字符时限制显示结果。怎么做?

回答by chrisvillanueva

for the record:

作为记录:

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.

在自动完成激活之前用户必须键入的最少字符数。零对于只有几个项目的本地数据很有用。当有很多项目时应该增加,其中单个字符将匹配几千个项目。

Code examples

代码示例

Initialize a autocomplete with the minLength option specified.

使用指定的 minLength 选项初始化自动完成。

$( ".selector" ).autocomplete({ minLength: 0 });

Get or set the minLength option, after init.

在 init 之后获取或设置 minLength 选项。

//getter
var minLength = $( ".selector" ).autocomplete( "option", "minLength" );
//setter
$( ".selector" ).autocomplete( "option", "minLength", 0 );

minLengthIntegerDefault:1

minLengthIntegerDefault:1

docs

文档

回答by Raab

$( "#myselectbox" ).autocomplete({ minLength: 2 });

回答by rickul

There is no minLength attribute. The attribute you are searching for is minChars.

没有 minLength 属性。您正在搜索的属性是minChars

see https://github.com/devbridge/jQuery-Autocomplete

https://github.com/devbridge/jQuery-Autocomplete