You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.3 KiB
46 lines
1.3 KiB
var province=$("#province"),city=$("#city"),town=$("#town");
|
|
for(var i=0;i<provinceList.length;i++){
|
|
addEle(province,provinceList[i].name);
|
|
}
|
|
function addEle(ele,value){
|
|
var optionStr="";
|
|
optionStr="<option value="+value+">"+value+"</option>";
|
|
ele.append(optionStr);
|
|
}
|
|
function removeEle(ele){
|
|
ele.find("option").remove();
|
|
var optionStar="<option value="+"请选择"+">"+"请选择"+"</option>";
|
|
ele.append(optionStar);
|
|
}
|
|
var provinceText,cityText,cityItem;
|
|
province.on("change",function(){
|
|
provinceText=$(this).val();
|
|
$.each(provinceList,function(i,item){
|
|
if(provinceText == item.name){
|
|
cityItem=i;
|
|
return cityItem
|
|
}
|
|
});
|
|
removeEle(city);
|
|
removeEle(town);
|
|
$.each(provinceList[cityItem].cityList,function(i,item){
|
|
addEle(city,item.name)
|
|
})
|
|
});
|
|
city.on("change",function(){
|
|
cityText=$(this).val();
|
|
removeEle(town);
|
|
$.each(provinceList,function(i,item){
|
|
if(provinceText == item.name){
|
|
cityItem=i;
|
|
return cityItem
|
|
}
|
|
});
|
|
$.each(provinceList[cityItem].cityList,function(i,item){
|
|
if(cityText == item.name){
|
|
for(var n=0;n<item.areaList.length;n++){
|
|
addEle(town,item.areaList[n])
|
|
}
|
|
}
|
|
});
|
|
}); |