$(document).ready(function () {initCityPick();});回复
只有省的下拉能出来,区和县都出不来
有BUG,选择province,再选择city后,province恢复请选择,city会变为请选择,但依然有选项不能清空。
该BUG分别在省和市的change事件加上判断即可,如下:
province.on("change",function(){ provinceText=$(this).val(); $.each(provinceList,function(i,item){ if(provinceText == item.name){ cityItem=i; return cityItem } }); removeEle(city); removeEle(town); if(provinceText === "请选择") return; $.each(provinceList[cityItem].cityList,function(i,item){ addEle(city,item.name) }) }); city.on("change",function(){ cityText=$(this).val(); removeEle(town); if(cityText === "请选择") return; $.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]) } } }); });