[英]How do I limit jQuery auto complete by length entered if condition?
I am trying to get jQuery autocomplete to start only when 3 or more letters have been entered in the textbox. 我试图让jQuery自动完成功能仅在文本框中输入3个或更多字母时才启动。 Currently it starts as soon as the first character has been entered.
目前,它是在输入第一个字符后立即开始的。 Here is what I have tried:
这是我尝试过的:
if ("#<%= TextBox1.ClientID %>".length >=3 ) {
$(function () {
var availableTags = [ <%= SuggestionList %>];
$("#<%= TextBox1.ClientID %>").autocomplete({
source: availableTags
});
});
}
this still fires after the first charecter has been entered. 输入第一个字符后仍会触发。
Your code will look something like this generated: 您的代码将如下所示:
if("#myId".length >=3 ) {
In other words, you're checking the length of the string, which doesn't make much sense. 换句话说,您正在检查字符串的长度,这没有多大意义。 You should be using the
minLength
option of autocomplete: 您应该使用自动完成的
minLength
选项:
$("#<%= TextBox1.ClientID %>").autocomplete({
minLength: 3,
source: availableTags
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.