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

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

问题描述

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

$(".cmbBox").combobox({改变:功能(){警报($(this).val());}});

当值发生变化时,会提醒更新的值.

请提供任何帮助.. :)

解决方案

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

/* 截图 */选择:函数(事件,用户界面){ui.item.option.selected = true;self._trigger(选择",事件,{项目:ui.item.option});select.trigger("改变");},/* 截图 */

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

$(".cmbBox").change(function() {警报(这个.值);});

不幸的是,这与正常的 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天全站免登陆