【问题标题】:jQuery combobox , how to trigger the select eventjQuery组合框,如何触发选择事件
【发布时间】:2012-09-21 07:49:42
【问题描述】:

您好,我正在为我的codeigniter 应用程序使用jquery combo-box

有 3 个组合框。当国家/地区值改变时,州组合框再次使用新值创建,当州组合框值改变时,城市组合框使用新值创建。

它第一次工作正常,但在表单提交后,城市和州下拉更改事件不起作用。

国家组合框更改事件起作用,在我更改国家组合框值后,状态组合更改事件再次起作用。

我认为这里的问题是

1.国家组合框事件在国家组合框改变之前不会绑定。 2.城市组合框事件在状态组合框改变之前不绑定。

** 那么有没有办法在文档就绪时触发国家组合框选择事件。

提前致谢...........

这是我的 jquery

jQuery('#combolist_country').combobox({
        selected: function(event, ui) {

            jQuery('#combolist_state').combobox().empty();
            jQuery('#combolist_city').combobox().empty();

            dataVal = jQuery(this).val();

            jQuery.ajax({
                type :  'POST',
                url  :  baseurl + "/search_by_country",
                data: {country_id:dataVal},
                dataType:'json',
                success: function(data)
                {
                    if(data)
                    {
                        var data_arr=data;
                        if(jQuery.isArray(data_arr['state_list']) && data_arr['state_list'].length > 0){
                            var aList = data_arr['state_list'];
                            var sKey;
                            jQuery("#combolist_state").combobox('destroy').empty();
                            jQuery('#combolist_state').removeAttr('disabled');
                            jQuery("#combolist_state").append('<option value="0">Select State</option>');           
                            for (sKey in aList) {
                                jQuery("#combolist_state").append('<option value="' + aList[sKey].StateID + '">' + aList[sKey].StateName + '</option>');
                            }
                            jQuery("#combolist_state").combobox({
                                selected:function(){

                                    jQuery('#combolist_city').combobox().empty();
                                    jQuery('#combolist_neighborhood').combobox().empty();

                                    dataVal = jQuery(this).val();

                                    jQuery.ajax({
                                        type :  'POST',
                                        url  :  baseurl + "search_by_state",
                                        data: {state_id:dataVal},
                                        dataType:"json",
                                        success: function(data)
                                        {
                                            if(data)
                                            {
                                                var data_arr=data;                                  
                                                if(jQuery.isArray(data_arr['city_list']) && data_arr['city'] == 1 && data_arr['city_list'].length > 0){

                                                    var aList = data_arr['city_list'];
                                                    var sKey;
                                                    jQuery("#combolist_city").combobox('destroy').empty();
                                                    jQuery('#combolist_city').removeAttr('disabled');
                                                    jQuery("#combolist_city").append('<option value="0">Select City</option>');         
                                                    for (sKey in aList) {
                                                        jQuery("#combolist_city").append('<option value="' + aList[sKey].CityID + '">' + aList[sKey].CityName + '</option>');
                                                    }  

                                                    jQuery('#combowrap_combolist_city').fadeTo('slow',1);

                                                }                                                   
                                            }                                                                                       
                                        }  
                                    });
                                }
                            });  

                            jQuery('#combowrap_combolist_state').fadeTo('slow',1);                          

                        } 
                    } 
                }                   
            });
        }
});

【问题讨论】:

标签: javascript jquery jquery-ui codeigniter


【解决方案1】:

只需使用jQuery("#combolist_state").html(list_of_options) 重新填充您的组合框并保留事件,而不是销毁和重新创建组合框和事件。

var list_of_options = '';
for (sKey in aList)
    list_of_options +='<option value="' + aList[sKey].StateID + '">' + aList[sKey].StateName + '</option>';
jQuery("#combolist_state").html(list_of_options)

【讨论】:

    【解决方案2】:

    试试这个

    $('#combolist_country').combobox({
            selected: function (event, ui) {
                var id = ui.item.value;
                if (id > 0) {
                    //Fill Drop Down for State and Add Similar logic for City and Pincode
                }
            }
        });
    

    希望这会奏效!

    【讨论】:

      【解决方案3】:

      我不确定这是否能解决您的问题,但我最近在组合框和自动回发等方面遇到了同样的问题...

      我在我的 jQuery 中添加了以下内容:

          function pageLoad() {
              // Your functionality here
          }
      
          Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoad); 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-02-12
        • 1970-01-01
        • 2021-01-20
        • 2023-04-04
        • 1970-01-01
        • 2016-11-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多