How do you trigger autocomplete “select” event manually in jQueryUI?

后端 未结 10 1373
别跟我提以往
别跟我提以往 2020-12-01 09:28

I\'m using jQueryUI autocomplete, and I have a function mapped to the select event, e.g.:

$(\"#someId\").autocomplete({
    source: someData,
    select: fun         


        
相关标签:
10条回答
  • 2020-12-01 09:52

    You could do:

    $("#someId").trigger("autocompleteselect");
    
    0 讨论(0)
  • 2020-12-01 09:55

    You can do it the way the jQuery team does it in their unit tests - see this answer

    0 讨论(0)
  • 2020-12-01 09:57

    Simply call following function

    setAutocomplete("#txt_User_Name","rohit");

    function setAutocomplete(autocompleteId,valuetoset)
        {
            $(autocompleteId).val(valuetoset);
            $(autocompleteId).autocomplete("search", valuetoset);
            var list = $(autocompleteId).autocomplete("widget");
            $(list[0].children[0]).click();
        }
    
    0 讨论(0)
  • 2020-12-01 10:01

    You don't have to go through a bunch of rigmarole to call select. This is how I call select from my own extended version of autocomplete.

    $(this).data('ui-autocomplete').options.select(event, ui);
    

    where I use this

    /**
     * The jQuery UI plugin autocomplete
     */
    $.widget( "ui.autocomplete", $.ui.autocomplete, {
       options: {
          close: function( event, ui ) {
             if (typeof event.currentTarget == 'undefined') {
                $(this).val("");
                $(this).data('ui-autocomplete').options.select(event, ui);
             }
          }
       }
     });
    
    0 讨论(0)
提交回复
热议问题