Javascript second-level interaction and javascript Interaction

Source: Internet
Author: User

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.

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.