完成,bug修复

This commit is contained in:
landaiqing 2023-05-01 21:47:33 +08:00
parent 71d37fac5f
commit 381fefa889
2 changed files with 21 additions and 18 deletions

View File

@ -34,9 +34,15 @@
// console.log(FatherId); // console.log(FatherId);
getCity(CountryId); getCity(CountryId);
CityID=$("#city").val(); CityID=$("#city").val();
console.log(CityID); // console.log(CityID);
getArea(CityID); getArea(CityID);
}); });
$("#city").change(function(){
CityID=$("#city").val();
// console.log(CityID);
getArea(CityID);
})
}) })
</script> </script>

View File

@ -17,15 +17,6 @@ function getData(){
function getCountry(){ function getCountry(){
// $.ajax({
// url : './json/third-level-address.json',
// type : 'get',
// async: false,
// success : function(data) {
// if(data=="error"){
// alert("系统错误");
// return;
// }
var data = getData(); var data = getData();
var country = new Array(); var country = new Array();
var children = new Array(); var children = new Array();
@ -36,9 +27,8 @@ function getCountry(){
children.push(tmp.children); children.push(tmp.children);
}); });
// for(var i in data){ // for(var i in data){
// console.log(data[i].children[0].children[0].code); // console.log(data[i].children[0].children.length);
// } // }
// console.log(data[0].children[1].name);
var options = "<option value='0'>--请选择--</option>"; var options = "<option value='0'>--请选择--</option>";
for(var i in data){ for(var i in data){
options += "<option value='" + data[i].code + "' selected>" + dataJson[i].name+"</option>"; options += "<option value='" + data[i].code + "' selected>" + dataJson[i].name+"</option>";
@ -52,8 +42,11 @@ function getCity(countryCode){
$('#city').empty(); $('#city').empty();
var options = "<option value='0'>--请选择--</option>"; var options = "<option value='0'>--请选择--</option>";
for(var i in data){ for(var i in data){
for(let j=0;j<data[i].children.length;j++){
if(countryCode && countryCode == data[i].code){ if(countryCode && countryCode == data[i].code){
options += "<option value='" + data[i].children[0].code + "' selected>" + data[i].children[0].name+"</option>"; options += "<option value='" + data[i].children[j].code + "' selected>" + data[i].children[j].name+"</option>";
}
} }
$("#city").html(options); $("#city").html(options);
} }
@ -63,9 +56,13 @@ function getArea(cityCode){
var data = getData(); var data = getData();
var options = "<option value='0'>--请选择--</option>"; var options = "<option value='0'>--请选择--</option>";
for(var i in data){ for(var i in data){
if(cityCode && cityCode == data[i].children[0].code){ for(let j=0;j<data[i].children.length;j++){
options += "<option value='" + data[i].children[0].children[0].code + "' selected>" + data[i].children[0].children[0].name+"</option>"; for(let k=0;k<data[i].children[j].children.length;k++){
if(cityCode && cityCode == data[i].children[j].code){
options += "<option value='" + data[i].children[j].children[k].code + "' selected>" + data[i].children[j].children[k].name+"</option>";
} }
}
}
$("#area").html(options); $("#area").html(options);
} }