尊重劳动成果,转载请注明出处(http://blog.csdn.net/sllailcp/article/details/41382503)...
以下是部分json数据,根据省市区的id,返回里面相对应的省市区名字,直接放到script标签中即可运行得到结果;
<script type="text/javascript">
var province_enum = [
{id: 1, name: ‘北京‘, city: [
{id: 1, name: ‘北京市‘, district: [
{id: 1, name: ‘东城区‘},
{id: 2, name: ‘西城区‘},
{id: 3, name: ‘崇文区‘},
{id: 4, name: ‘宣武区‘},
{id: 5, name: ‘朝阳区‘},
{id: 6, name: ‘丰台区‘},
{id: 7, name: ‘石景山区‘},
{id: 8, name: ‘海淀区‘},
{id: 9, name: ‘门头沟区‘},
{id: 10, name: ‘房山区‘},
{id: 11, name: ‘通州区‘},
{id: 12, name: ‘顺义区‘},
{id: 13, name: ‘昌平区‘},
{id: 14, name: ‘大兴区‘},
{id: 15, name: ‘怀柔区‘},
{id: 16, name: ‘平谷区‘},
{id: 17, name: ‘密云县‘},
{id: 18, name: ‘延庆县‘}
]}
]},
{id: 2, name: ‘天津‘, city: [
{id: 2, name: ‘天津市‘, district: [
{id: 19, name: ‘和平区‘},
{id: 20, name: ‘河东区‘},
{id: 21, name: ‘河西区‘},
{id: 22, name: ‘南开区‘},
{id: 23, name: ‘河北区‘},
{id: 24, name: ‘红桥区‘},
{id: 25, name: ‘塘沽区‘},
{id: 26, name: ‘汉沽区‘},
{id: 27, name: ‘大港区‘},
{id: 28, name: ‘东丽区‘},
{id: 29, name: ‘西青区‘},
{id: 30, name: ‘津南区‘},
{id: 31, name: ‘北辰区‘},
{id: 32, name: ‘武清区‘},
{id: 33, name: ‘宝坻区‘},
{id: 34, name: ‘宁河县‘},
{id: 35, name: ‘静海县‘},
{id: 36, name: ‘蓟县‘}
]}
]},
]
function getProvivce(Provivceid,Cityid,Areaid)
{
for(var x=0;x<province_enum.length;x++){
if(Provivceid==province_enum[x].id){
var Provivce=(province_enum[x].name);
for(var y=0;y<province_enum[x].city.length;y++){
if(Cityid==province_enum[x].city[y].id){
var City=(province_enum[x].city[y].name);
for(var z=0;z<province_enum[x].city[y].district.length;z++){
if(Areaid==province_enum[x].city[y].district[z].id){
var Area=(province_enum[x].city[y].district[z].name);
return alert(Provivce+‘,‘+City+‘,‘+Area);
}
}
}
}
}
}
}
getProvivce(2,2,19)
</script>
结果如图所示: