jQuery AutoComplete Trigger Change Event

后端 未结 13 1074
陌清茗
陌清茗 2020-11-27 15:50

How do you trigger jQuery UI\'s AutoComplete change event handler programmatically?

Hookup

$(\"#CompanyList\").autocomplete({ 
    s         


        
13条回答
  •  旧巷少年郎
    2020-11-27 16:28

    Here is a relatively clean solution for others looking up this topic:

    // run when eventlistener is triggered
    $("#CompanyList").on( "autocompletechange", function(event,ui) {
       // post value to console for validation
       console.log($(this).val());
    });
    

    Per api.jqueryui.com/autocomplete/, this binds a function to the eventlistener. It is triggered both when the user selects a value from the autocomplete list and when they manually type in a value. The trigger fires when the field loses focus.

提交回复
热议问题