Returns the name of the provincial city according to the province's urban ID

Source: Internet
Author: User


Respect the fruits of labor, reprint please indicate the source (http://blog.csdn.net/sllailcp/article/details/41382503) ...

The following is a partial JSON data, according to the provincial city ID, return the corresponding provincial and municipal names, directly into the script tag can be run to get results;


<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 Area '},            {id:3, Name: ' Chongwen District '},            {id:4, Name: ' Xuanwu '},            {id:5, Name: ' Chaoyang District '},            {id:6, n Ame: ' Fengtai '},            {id:7, Name: ' Shijingshan District '},            {ID: 8, Name: ' Haidian '},            {id:9, Name: ' Mentougou District '},            {id:10, Name: ' Fangshan '},            {id:11, name: ' Tongzhou District '},            {id:12, name: ' Shunyi District '},            {id:13, name: ' Changping District '},        & nbsp   {id:14, NAMe: ' Daxing District '},            {id:15, Name: ' Huairou '},            {ID: +, Name: ' Pinggu District '},            {id:17, Name: ' Miyun '},            {id:18, Name: ' Yanqing County '}       ]}   ]},    {id:2, Name: ' Tianjin ', City: [  &nbsp ;     {id:2, Name: ' Tianjin ', District: [            {id:19, Name: ' Heping District '},  &nbsp ;         {id:20, Name: ' Hedong '},            {id:21, Name: ' Hexi District '},  & nbsp         {id:22, name: ' Nankai District '},            {id:23, Name: ' Hebei District '},  & nbsp         {id:24, name: ' Hongqiao District '},            {id:25, name: ' Tanggu District '},  & nbsp         {id:26, name: ' Hangu District '},            {id:27, name: ' Grand Port District '},  & nbSp         {id:28, name: ' Dongli District '},            {id:29, name: ' Xiqing District '},  & nbsp         {id:30, name: ' Jinnan District '},            {id:31, Name: ' Beichen District '},  & nbsp         {id:32, name: ' Wuqing District '},            {id:33, name: ' Baochi District '},  & nbsp         {id:34, name: ' Ninghe County '},            {id:35, name: ' Jinghai County '},  & nbsp         {id:36, Name: ' Jixian '}       ]}   ]},]

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>



Results:


Returns the name of the provincial city according to the province's urban ID

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.