我还在学习php,但是当我想使用jquery,ajax,php和mysql创建一个4动态依赖下拉列表时,我遇到了这个问题。我能够发现一个有效的代码但是当我尝试编辑jquery代码时它不起作用。难道我做错了什么?。我已经复制了编辑代码和工作代码进行调试。我想创建一个4动态选择框,其中包含以下内容。 Oldgroup,group,district和address。善意的帮助。提前谢谢。
编辑代码 编辑后的代码采用jquery格式。 id是旧组,组,区和地址。
$(document).ready(function() {
//Change in continent dropdown list will trigger this function and
//generate dropdown options for county dropdown
$(document).on('change','#oldgroup', function() {
var oldgroup_id = $(this).val();
if(oldgroup_id != "") {
$.ajax({
url:"get_data.php",
type:'POST',
data:{oldgroup_id:oldgroup_id},
success:function(response) {
//var resp = $.trim(response);
if(response != '') {
$("#group").removeAttr('disabled','disabled').html(response);
$("#district").attr('disabled','disabled').html("<option value=''>------- Select --------</option>");
} else {
$("#group, #district, #address").attr('disabled','disabled').html("<option value=''>------- Select --------</option>");
}
}
});
} else {
$("#group, #district, #address").attr('disabled','disabled').html("<option value=''>------- Select --------</option>");
}
});
//Change in coutry dropdown list will trigger this function and
//generate dropdown options for state dropdown
$(document).on('change','#group', function() {
var group_id = $(this).val();
if(group_id != "") {
$.ajax({
url:"get_data.php",
type:'POST',
data:{group_id:group_id},
success:function(response) {
//var resp = $.trim(response);
if(response != '') $("#district").removeAttr('disabled','disabled').html(response);
else $("#district, #address").attr('disabled','disabled').html("<option value=''>------- Select --------</option>");
}
});
} else {
$("#district, #address").attr('disabled','disabled').html("<option value=''>------- Select --------</option>");
}
});
//Change in state dropdown list will trigger this function and
//generate dropdown options for city dropdown
$(document).on('change','#district', function() {
var district_id = $(this).val();
if(district_id != "") {
$.ajax({
url:"get_data.php",
type:'POST',
data:{district_id:district_id},
success:function(response) {
if(response != '') $("#address").removeAttr('disabled','disabled').html(response);
else $("#address").attr('disabled','disabled').html("<option value=''>------- Select --------</option>");
}
});
} else {
$("#address").attr('disabled','disabled').html("<option value=''>------- Select --------</option>");
}
});
工作代码 - 这是具有 - 大陆,国家,州和城市的工作代码我想创建一个4动态选择框,其中包含以下内容。 Oldgroup,group,district和address。善意的帮助。提前谢谢。
$(document).ready(function()
//Change in continent dropdown list will trigger this function and
//generate dropdown options for county dropdown
$(document).on('change','#continent', function() {
var continent_id = $(this).val();
if(continent_id != "") {
$.ajax({
url:"get_data.php",
type:'POST',
data:{continent_id:continent_id},
success:function(response) {
//var resp = $.trim(response);
if(response != '') {
$("#country").removeAttr('disabled','disabled').html(response);
$("#state").attr('disabled','disabled').html("<option value=''>------- Select --------</option>");
} else {
$("#country, #state, #city").attr('disabled','disabled').html("<option value=''>------- Select --------</option>");
}
}
});
} else {
$("#country, #state, #city").attr('disabled','disabled').html("<option value=''>------- Select --------</option>");
}
});
//Change in coutry dropdown list will trigger this function and
//generate dropdown options for state dropdown
$(document).on('change','#country', function() {
var country_id = $(this).val();
if(country_id != "") {
$.ajax({
url:"get_data.php",
type:'POST',
data:{country_id:country_id},
success:function(response) {
//var resp = $.trim(response);
if(response != '') $("#state").removeAttr('disabled','disabled').html(response);
else $("#state, #city").attr('disabled','disabled').html("<option value=''>------- Select --------</option>");
}
});
} else {
$("#state, #city").attr('disabled','disabled').html("<option value=''>------- Select --------</option>");
}
});
//Change in state dropdown list will trigger this function and
//generate dropdown options for city dropdown
$(document).on('change','#state', function() {
var state_id = $(this).val();
if(state_id != "") {
$.ajax({
url:"get_data.php",
type:'POST',
data:{state_id:state_id},
success:function(response) {
if(response != '') $("#city").removeAttr('disabled','disabled').html(response);
else $("#city").attr('disabled','disabled').html("<option value=''>------- Select --------</option>");
}
});
} else {
$("#city").attr('disabled','disabled').html("<option value=''>------- Select --------</option>");
}
});
});