JS to achieve District linkage

Source: Internet
Author: User

1. The introduction of county and county linkage function as follows, the provincelist data to the need for linkage of data information

varAddressinit =function(_cmbprovince, _cmbcity, _cmbarea, _cmbstreet, Defaultprovince, defaultcity, Defaultarea,defaultstreet) {
    varCmbprovince =document.getElementById (_cmbprovince); varCmbcity =document.getElementById (_cmbcity); varCmbarea =document.getElementById (_cmbarea); varCmbstreet =document.getElementById (_cmbstreet); functionCmbselect (CMB, str) { for(vari=0; i<cmb.options.length; i++)            {                if(Cmb.options[i].value = =str) {Cmb.selectedindex=i; return; }            }        }        functioncmbaddoption (CMB, str, obj, num) {varoption = document.createelement (' option ');            Cmb.options.add (option); Option.innertext=str; Option.value=num; Option.obj=obj; Console.log (num)}functionchangeprovince () {cmbCity.options.length= 0; Cmbcity.onchange=NULL; if(Cmbprovince.selectedindex = =-1)return; varitem =Cmbprovince.options[cmbprovince.selectedindex].obj; /**console.log (item) **/             for(vari=0; i<item.citylist.length; i++) {cmbaddoption (cmbcity, Item.citylist[i].name, item.citylist[i],item.citylist[i].sleep);        } cmbselect (Cmbcity, defaultcity); }                 for(vari=0; i<provincelist.length; i++) {cmbaddoption (cmbprovince, Provincelist[i].name, provincelist[i],provincelist[i].sleep);        } cmbselect (Cmbprovince, defaultprovince);        Changeprovince (); Cmbprovince.onchange=changeprovince; }    /*All sleep used is a custom attribute, and sleep can be customized to specify data to facilitate front-end data interaction*/    varProvincelist =[{name:' All ', sleep: ' 0 ',//Provincialcitylist:[//City Level{name: ' All ', sleep: ' 0 ', arealist:[//District County{name: ' All ', sleep: ' 0 '}]}]}, {name:' Shaanxi Province ', Sleep: ' 1 ', citylist:[{name:' All ', sleep: ' 0 ', arealist:[{name:' All ', sleep: ' 0 '}]}, {name:' Xian City ', Sleep: ' 1 ', arealist:[{name:' All ', sleep: ' 0 '}, {name:' 鄠 district ', Sleep: ' 1 '}, {name:' Hi-tech zone ', sleep: ' 2 '}]}, {name:' Weinan ', Sleep: ' 2 ', arealist:[{name:' All ', sleep: ' 0 '}, {name:' Dali County ', Sleep: ' 1 '}, {name:' Pucheng County ', Sleep: ' 2 '}]}]}, {name:' Zhejiang province ', Sleep: ' 2 ', citylist:[{name:' All ', sleep: ' 0 ', arealist:[{name:' All ', sleep: ' 0 '}, {name:' Hangzhou city ', Sleep: ' 1 '}, {name:' Ningbo ', Sleep: ' 2 '}]}, {name:' Hangzhou city ', Sleep: ' 1 ', arealist:[{name:' All ', sleep: ' 0 '}, {name:' Xiaoshan District ', Sleep: ' 1 '}, {name:' Fuyang district ', Sleep: ' 2 '}]}, {name:' Ningbo ', Sleep: ' 2 ', arealist:[{name:' All ', sleep: ' 0 '}, {name:' Koto Ward ', Sleep: ' 1 '}, {name:' Zhenhai District ', Sleep: ' 2 '}                ]            }                         ]    }]; 

2. Call the Addressinit () linkage function on a page that requires linkage

Addressinit (' Province id ', ' City id ', ' County ID '); // Drop- down box select linkage

JS to achieve District linkage

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.