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

前端 未结 3 1357
醉话见心
醉话见心 2021-02-20 15:49

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?

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-20 16:48

    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.

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

    Get or set the minLength option, after init.

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

    minLengthIntegerDefault:1

    docs

提交回复
热议问题