注册|登录

联系电话:024-31891684  13390130939
沈阳软件公司--沈阳软件定制

沈阳软件开发_沈阳软件公司_沈阳软件定制/软件/最新技术

Latest technology最新技术

js级联

浏览量:2358

<!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>
<title>级联</title>
</head>
<body onload="addpro()">
<div>
<table>
<tr>
<td>
<select id="pro" style="width:110px;" onchange="addcity()">
<option>=请选择省份=</option>
</select>
</td>
<td>
<select id="city" style="width:100px;">
<option>=请选择市=</option>
</select>
</td>
</tr>
</table>

</div>

<script type="text/javascript">
var pro = [{ value: '3', name: '江苏' }, { value: '4', name: '上海'}];
var city = [{ code: '3', name: '南京' }, { code: '3', name: '苏州' }, { code: '3', name: '常州' }, { code: '3', name: '无锡' }, { code: '3', name: '镇江' }, { code: '4', name: '徐汇区' }, { code: '4', name: '闵行区' }, { code: '4', name: '嘉定区'}];
function addpro() {
for (i = 0; i < pro.length; i++) {
document.getElementById("pro").add(new Option(pro[i]["name"], pro[i]["value"]));
}
}
function addcity() {
document.getElementById("city").length=1;
var objselect = document.getElementById("pro").options(document.getElementById("pro").selectedIndex);
for (i = 0; i < city.length; i++) {
if (city[i]["code"] == objselect.value) {
document.getElementById("city").add(new Option(city[i]["name"], city[i]["name"]));
}
}
}
</script>
</body>
</html>

沈阳团购网|营口网站制作|沈阳软件公司|软件定制|网站建设|加盟易势|提交问题