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