根據省市區的id返回省市區的名字,id返回省市區

來源:互聯網
上載者:User

根據省市區的id返回省市區的名字,id返回省市區


尊重勞動成果,轉載請註明出處(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>



結果:


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.