Return the name of a province or city based on the province or city id.

Source: Internet
Author: User

Return the name of a province or city based on the province or city id.


Respect for labor results, reproduced please indicate the source (http://blog.csdn.net/sllailcp/article/details/41382503 )...

The following are some json data. Based on the province/city id, return the corresponding province/city name and directly put it in the script tag to run the result;


<Script type = "text/javascript">

Var province_enum = [{id: 1, name: 'beijing', city: [{id: 1, name: 'beijing', district: [{id: 1, name: 'dongcheng district '}, {id: 2, name: 'xicheng district'}, {id: 3, name: 'chongwen district '}, {id: 4, name: 'xuanwu district '}, {id: 5, name: 'chaoyang district'}, {id: 6, name: 'fengtai district '}, {id: 7, name: 'shijingshan district '}, {id: 8, name: 'haidian district'}, {id: 9, name: 'mentougou district '}, {id: 10, name: 'fangshan district '}, {id: 11, name: 'tongzhou district'}, {id: 12, name: 'shunyi district '}, {id: 13, name: 'changping district '}, {id: 14, name: 'daxing district'}, {id: 15, name: 'huairou district '}, {id: 16, name: 'pinggu district '}, {id: 17, name: 'miyun County'}, {id: 18, name: 'yanqing County '}]}, {id: 2, name: 'tianjin ', city: [{id: 2, name: 'tianjin', district: [{id: 19, name: 'heping region'}, {id: 20, name: 'heudong district '}, {id: 21, name: 'hexi district'}, {id: 22, name: 'nankai district '}, {id: 23, name: 'hebei district '}, {id: 24, name: 'hongqiao district'}, {id: 25, name: 'tanggu region'}, {id: 26, name: 'hangzhou'}, {id: 27, name: 'dagang district '}, {id: 28, name: 'dongli region'}, {id: 29, name: 'xiqing district '}, {id: 30, name: 'jinnan district'}, {id: 31, name: 'beichen district '}, {id: 32, name: 'wuqing district '}, {id: 33, name: 'baodi region'}, {id: 34, name: 'ninghe County'}, {id: 35, name: 'jinghai County '}, {id: 36, name: 'yixian County'}]},]

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>



Result:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.