简体   繁体   中英

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. 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:

$("#<%= TextBox1.ClientID %>").autocomplete({
    minLength: 3,
    source: availableTags
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM