您好我在jquery combo-box
申请中使用codeigniter
,
有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);
}
}
}
});
}
});
答案 0 :(得分:0)
只需使用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)
答案 1 :(得分:0)
试试这个
$('#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
}
}
});
希望这会奏效!
答案 2 :(得分:-1)
我不确定这是否能解决您的问题,但我最近遇到了与组合框和自动回复等问题相同的问题......
我在jQuery中添加了以下内容:
function pageLoad() {
// Your functionality here
}
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoad);