jquery UI Combobox ONCHANGE

前端 未结 8 991
死守一世寂寞
死守一世寂寞 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:01

    The combobox example source is all right there in the example. I'd trigger the change event of the underlying select by modifying the source code like this (changing the select event handler inside autocomplete initialization inside the plugin):

    /* Snip */
    select: function( event, ui ) {
        ui.item.option.selected = true;
        self._trigger( "selected", event, {
            item: ui.item.option
        });
        select.trigger("change");                            
    },
    /* Snip */
    

    and then define an event handler for the regular change event of the select:

    $(".cmbBox").change(function() {
        alert(this.value);
    });
    

    Unfortunately this won't work exactly the same way as the normal select.change event: it will trigger even you select the same item from the combobox.

    Try it out here: http://jsfiddle.net/andrewwhitaker/hAM9H/

提交回复
热议问题