Second-level linkage in general web pages everywhere, generally is the address, such as click on Zhejiang province, followed by Hangzhou, Jiaxing; Click on the Beijing province appears Chaoyang, Haidian, instead of appearing in Hangzhou, Jiaxing.
To implement this step, JavaScript is used. Where the principle is used to onchange time.
First, the onchange event occurs when the contents of the domain change. JavaScript objects that support this event: FileUpload, select, text, textarea, we are using Select to achieve level two linkage.
The following is the HTML code, first set a select for the province, the second select for the city, but the city we use an array in JS to connect it with the province.
<! DOCTYPE html>
Here is the JS code
var province = document.getElementById ("province"), var city = document.getElementById ("city"), var area = [[' Chaoyang ', ' Haidian ', ' Beijing '],//array of the No. 0 area. 0{0,1,2}[' Hangzhou ', ' haining ']//1th area array, 1{0.1}]; function choose () {var opt = ""; var len = Area[province.value]; If you choose Beijing 0, then, len=[' Chaoyang ', ' Haidian ' This is the link which province corresponds to which cityCity'sThe array if (Province.value = = '-1 ') {//Because the value of select IS-1 is the word ' province ' instead of Beijing, so when we choose this province it corresponds to let his city be empty city.innerhtml = Opt } for (var i = 0;i < Len.length; i++) {//area array number for (i = 0;i < 3; i++) opt = opt + ' <option value = "' + i + ' "> ' + len[i]+ ' </option> '//opt =" "+ <option value =" 0 "> Chaoyang (lin[0]) </option> opt = <option value = "0" > Chaoyang (lin[0]) </option>
<option value = "1" > Haidian (lin[1]) </option> opt = <option value = "0" > Chaoyang (lin[0]) </option>
<option value = "1" > Haidian (lin[1]) </option> +
<option value = "2" > Beijing (lin[2]) </option>} city.innerhtml = opt;} Province.onchange = function () {choose ();}Second-level linkage in general web pages everywhere, generally is the address, such as click on Zhejiang province, followed by Hangzhou, Jiaxing; Click on the Beijing province appears Chaoyang, Haidian, instead of appearing in Hangzhou, Jiaxing.
To implement this step, JavaScript is used. Where the principle is used to onchange time.
JavaScript two-level linkage