Javascript second-level interaction and javascript Interaction
Second-level linkage can be seen everywhere on general web pages. Generally, it is an address. For example, click Zhejiang Province, followed by Hangzhou and Jiaxing city. Click Beijing to see Chaoyang and Haidian, instead of Hangzhou, jiaxing.
To implement this step, javascript is required. The onchange time is used as the principle.
First, the onchange event occurs when the content of the domain changes. JavaScript objects that support this event: fileUpload, select, text, and textarea. select is used for implementation of level-2 interaction.
The following is the HTML code. First, set a select statement to province and the second select statement to city. However, we use arrays in js to connect the select statement to province.
<! DOCTYPE html>
Below is the js Code
Var province = document. getElementById ("province"); var city = document. getElementById ("city"); var area = [['chaoyang ', 'haidian', 'beijing'], // an array of 0th areas. 0 {1st, 2} ['hangzhou', 'haining '] // an array of 0.1 areas, 1 {}]; function choose () {var opt = ""; var len = area [province. value]; // if Beijing 0 is selected, len = ['chaoyang ', 'haidian'] indicates the array of cities corresponding to the province if (province. value = '-1') {// because the select value is-1, it is the word "save", not Beijing. Therefore, when we select this province, the city is empty. innerHTML = opt;} for (var I = 0; I <len. length; I ++) {// Number of arrays in the area 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 can be seen everywhere on general web pages. Generally, it is an address. For example, click Zhejiang Province, followed by Hangzhou and Jiaxing city. Click Beijing to see Chaoyang and Haidian, instead of Hangzhou, jiaxing.
To implement this step, javascript is required. The onchange time is used as the principle.