jQuery UI组合框ONCHANGE [英] jquery UI Combobox ONCHANGE

查看:110
本文介绍了jQuery UI组合框ONCHANGE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在jqueryUI组合框中附加onchange函数?这是我的代码:

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

值更改时,它将提醒更新的值.

请帮忙..:)

解决方案

组合框示例源在示例中就可以了.我将通过修改这样的源代码来触发基础选择的change事件(在插件内部的自动完成初始化中更改select事件处理程序):

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

,然后为select的常规change事件定义事件处理程序:

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

不幸的是,这与正常的select.change事件不能完全相同:即使您从组合框中选择相同的项目,它也会触发.

在此处尝试: http://jsfiddle.net/andrewwhitaker/hAM9H/

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

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

When the value changes, it will alert the updated value.

Any help please.. :)

解决方案

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/

这篇关于jQuery UI组合框ONCHANGE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆