jQuery AutoComplete Trigger Change Event

后端 未结 13 1061
陌清茗
陌清茗 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:46

    They are binding to keydown in the autocomplete source, so triggering the keydown will case it to update.

    $("#CompanyList").trigger('keydown');
    

    They aren't binding to the 'change' event because that only triggers at the DOM level when the form field loses focus. The autocomplete needs to respond faster than 'lost focus' so it has to bind to a key event.

    Doing this:

    companyList.autocomplete('option','change').call(companyList);
    

    Will cause a bug if the user retypes the exact option that was there before.

提交回复
热议问题