Try to set reminders, catch to capture return values
② Provinces and cities linkage
To fill the loop before emptying,
The code is as follows:
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>Document</title>
<script type= "Text/javascript" >
var arr = ["China", "USA", "Japan"];
arr["China" = ["Beijing", "Shanghai", "Guangzhou", "Shenzhen"];
arr["USA"] = ["New York", "Washington", "Los Angeles", "Chicago");
Arr["Japan"] = ["Tokyo", "Osaka", "Hokkaido"];
arr["Beijing"] = ["Beijing 1", "Beijing 2", "Beijing 3", "Beijing 4"];
arr["Shanghai" = ["Shanghai 1", "Shanghai 2", "Shanghai 3", "Shanghai 4"];
arr["guangzhou"] = ["Guangzhou 1", "Guangzhou 2", "Guangzhou 3", "Guangzhou 4"];
arr["Shenzhen" = ["Shenzhen 1", "Shenzhen 2", "Shenzhen 3", "Shenzhen 4"];
arr["New YORK"] = ["New York 1", "New York 2", "New York 3", "New York 4"];
Arr["WASHINGTON"] = ["Washington 1", "Washington 2", "Washington 3", "Washington 4"];
arr["Los ANGELES"] = ["Los Angeles 1", "Los Angeles 2", "Los Angeles 3", "Los Angeles 4"];
arr["Chicago"] = ["Chicago 1", "Chicago 2", "Chicago 3", "Chicago 4"];
Arr["Tokyo"] = ["Tokyo 1", "Tokyo 2", "Tokyo 3", "Tokyo 4"];
arr["Osaka"] = ["Osaka 1", "Osaka 2", "Osaka 3", "Osaka 4"];
arr["hokkaido") = ["Hokkaido 1", "Hokkaido 2", "Hokkaido 3", "Hokkaido 4"];
function AddData (arrdata,itemid) {
document.getElementById (itemID). length = 0;//First empties all the contents of the passed ID, and then adds
for (var i = 0; i<arrdata.length; i++) {
var option = new option ();//o uppercase,
Option.text = arrdata[i];//return to front face
Option.value = arrdata[i];//Returns the database value
document.getElementById (ItemID). Options.add (option);//options Fixed Assignment method
}
}
function Fun () {
AddData (arr, "country");
AddData (Arr[arr[0]], "province");
AddData (Arr[arr[arr[0]][0]], "area");
}
function Changepro (country) {
AddData (Arr[country], "province");
AddData (Arr[arr[country][0]], "area");//Trigger region, also show city corresponding region
}
function Changearea (province) {
AddData (Arr[province], "area");
}
</script>
<body onload= "Fun ()" >
Country: <select id= "Country" onchange= "Changepro (this.value)" ></select>
City: <select id= "Province" onchange= "Changearea (this.value)" ></select>
Location: <select id= "Area" ></select>
</body>
JavaScript Learning Second Lesson--① input judging ② provinces and cities linkage