jquery UI Combobox ONCHANGE

前端 未结 8 933
死守一世寂寞
死守一世寂寞 2020-12-02 13:28

how can I attach an onchange function in a jqueryUI combobox? Here is my code:

$(\".cmbBox\").combobox({
     change:function(){
         alert($(this).val()         


        
相关标签:
8条回答
  • 2020-12-02 14:06

    simplest way (IMHO), if you are deploying combobox as widget:

    1. find "_create" method in widget

    2. inside of it look for "autocomplete" (where input is managed)

    3. add (use) "select" method to get your data: ui.item.value

    
    (function($){
    $.widget( "ui.combobox", {
        // default options
        options: {
        //your options ....
        },
        _create: function() {
    
        //some code ....
    
        //this is input you look for
        input = $( "" )
        .appendTo( wrapper )
        .val( value )
        .addClass( "ui-state-default" )
    
        //this is autocomplete you look for
        .autocomplete({
            delay: 0,
            minLength: 0,
            source: function( request, response ) {
            //some code ...
            },
    
            //this is select method you look for ...
            select: function( event, ui ) {
    
            //this is your selected value
            console.log(ui.item.value);
            },
            change: function( event, ui ) {
    
            //some code ...
            }
        })
        //rest of code
        },
    
        destroy: function() {
        this.wrapper.remove();
        this.element.show();
        $.Widget.prototype.destroy.call( this );
        }
    });
    
    0 讨论(0)
  • 2020-12-02 14:12

    This seems to work for me

    if('function' == typeof(callback = ui.item.option.parentElement.onchange))
                            callback.apply(this, []);
    

    just before

    self._trigger("selected", event, {
    
    0 讨论(0)
提交回复
热议问题