标签:长沙 onchange doctype i++ 案例 ext 组元 hang 信息
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<select onchange="f(this)">
<option value="0">江西</option>
<option value="1">湖南</option>
<option value="2">广东</option>
</select>
<select id="selectCity">
<option value="0">南昌</option>
<option value="1">赣州</option>
<option value="2">吉安</option>
</select>
</body>
<script>
var citys = [["南昌", "赣州", "吉安"], ["长沙", "株洲", "潭州"], ["深圳", "广州", "惠州", "佛山"]];
var arr = null;
var selectOption = document.getElementById("selectCity");
var text = null;
var optionElement = null;
function f(obj) {
selectOption.innerHTML = "";
arr = citys[obj.value];
for (var i = 0; i < arr.length; i++) {
text = document.createTextNode(arr[i]); //将数组元素(城市)添加到text文档,节点
optionElement = document.createElement("option"); //创建选项元素来存储text信息
optionElement.appendChild(text); //将城市添加到选项元素
selectOption.appendChild(optionElement); //添加到选项
}
}
</script>
</html>
标签:长沙 onchange doctype i++ 案例 ext 组元 hang 信息
原文地址:https://www.cnblogs.com/21556guo/p/13447237.html