jQuery autoComplete view all on click?

后端 未结 22 1889
北恋
北恋 2020-12-02 09:52

I\'m using jQuery\'s autocomplete in a relatively simple way:

$(document).ready(function() {
  var data = [ {text: \"Choice 1\"}, 
               {text: \"Ch         


        
相关标签:
22条回答
  • 2020-12-02 10:06

    this is the only thing that works for me. List shows everytime and closes upon selection:

    $("#example")
    .autocomplete(...)
    .focus(function()
    {
      var self = this;
    
      window.setTimeout(function()
      {
        if (self.value.length == 0)
          $(self).autocomplete('search', '');
      });
    })
    
    0 讨论(0)
  • 2020-12-02 10:07

    You can trigger this event to show all of the options:

    $("#example").autocomplete( "search", "" );
    

    Or see the example in the link below. Looks like exactly what you want to do.

    http://jqueryui.com/demos/autocomplete/#combobox

    EDIT (from @cnanney)

    Note: You must set minLength: 0 in your autocomplete for an empty search string to return all elements.

    0 讨论(0)
  • 2020-12-02 10:07

    You must set minLength to zero in order to make this work! Here is the working example.

    $( "#dropdownlist" ).autocomplete({
          source: availableTags,
          minLength: 0 
        }).focus(function() {
          $(this).autocomplete('search', $(this).val())
        });
    });
    
    0 讨论(0)
  • 2020-12-02 10:08

    try this:

        $('#autocomplete').focus(function(){
            $(this).val('');
            $(this).keydown();
        }); 
    

    and minLength set to 0

    works every time :)

    0 讨论(0)
  • 2020-12-02 10:09

    I can't see an obvious way to do that in the docs, but you try triggering the focus (or click) event on the autocomplete enabled textbox:

    $('#myButton').click(function() {
       $('#autocomplete').trigger("focus"); //or "click", at least one should work
    });
    
    0 讨论(0)
  • 2020-12-02 10:11

    I could not get the $("#example").autocomplete( "search", "" ); part to work, only once I changed my search with a character that exists in my source it work. So I then used e.g. $("#example").autocomplete( "search", "a" );.

    0 讨论(0)
提交回复
热议问题