<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<select onchange="fun()" id="s"><!--选择后的事件-->
<option value="-1">请选择省</option>
<option value="0">广东省</option>
<option value="1">湖南省</option>
<option value="2">福建省</option>
</select>
<select id="ss">
</select>
<script>
var a = [
["广州","深圳","佛山"],
["长沙","岳阳","湘潭"],
["厦门","福州","泉州"],
];
function fun(){
var b = document.getElementById("s");
var c = b.value;//对应的值,设定时最好设与数组下标一一对应\
var d = a[c];//获取改省的城市
var e = document.getElementById("ss");
e.options.length = 0;//清空上一次的添加
for(var i = 0;i<d.length;i++){
var f = d[i];
var g = document.createElement("option");
var h = document.createTextNode(f);
g.appendChild(h);
e.appendChild(g);
}
}
</script>
</body>
</html>
10.2省市联动
最新推荐文章于 2024-04-14 22:05:41 发布