js二级联动下拉列表菜单
照着书打的源码,<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN"><html><head><title>Ne...
照着书打的源码,
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>New Document </title>
<script language="JavaScript" type="text/javascript">
<!--
var city=[
["北京","天津","上海","重庆"],
["南京","苏州","南通","常州"],
["福州","福安","龙岩","南平"],
["广州","潮阳","潮州","澄海"],
["兰州","白银","定西","敦煌"]
];
function getCity(){
var sltProvince=document.forms["theForm"].elements["province"];
var sltCity=document.forms["theForm"].elements["city"];
var provinceCity=city[sltProvince.selectedIndex-1];
sltCity.length=1;
for(var i=0;i<provinceCity.length;i++){
sltCity[i+1]=new Option(provinceCity[i],provinceCity[i]);
}
}
//-->
</script>
</head>
<body>
<form action="somepage.asp"name=theForm">
<select name="province" onchange="getCity()">
<option value="0">请选择所在省份</option>
<option value="直辖市">直辖市</option>
<option value="江苏省">江苏省</option>
<option value="福建省">福建省</option>
<option value="广东省">广东省</option>
<option value="甘肃省">甘肃省</option>
</select>
<select name="city">
<option value="0">请选择所在城市</option>
</select>
</form>
</body>
</html>
只能显示正常显示省份列表,选择省份后城市列表无变化啊,好像是少了城市的初始化吧 但是我不知道怎么添加 希望高手帮帮忙
没有分了 大家就行行好 义务献爱心了哈 谢谢
谢谢 ivws 确实好用了
那请问这是为什么呢?
刚才查了一下书,说是<!-- //->的作用是使不支持JavaScript的浏览器忽略脚本,但是,如果是支持JavaScript的浏览器还会忽略吗?不解诶。
感谢各位的回答,确实有收获,可是想知道这<!-- //->这个东西怎么会对代码效果有影响呢? 展开
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>New Document </title>
<script language="JavaScript" type="text/javascript">
<!--
var city=[
["北京","天津","上海","重庆"],
["南京","苏州","南通","常州"],
["福州","福安","龙岩","南平"],
["广州","潮阳","潮州","澄海"],
["兰州","白银","定西","敦煌"]
];
function getCity(){
var sltProvince=document.forms["theForm"].elements["province"];
var sltCity=document.forms["theForm"].elements["city"];
var provinceCity=city[sltProvince.selectedIndex-1];
sltCity.length=1;
for(var i=0;i<provinceCity.length;i++){
sltCity[i+1]=new Option(provinceCity[i],provinceCity[i]);
}
}
//-->
</script>
</head>
<body>
<form action="somepage.asp"name=theForm">
<select name="province" onchange="getCity()">
<option value="0">请选择所在省份</option>
<option value="直辖市">直辖市</option>
<option value="江苏省">江苏省</option>
<option value="福建省">福建省</option>
<option value="广东省">广东省</option>
<option value="甘肃省">甘肃省</option>
</select>
<select name="city">
<option value="0">请选择所在城市</option>
</select>
</form>
</body>
</html>
只能显示正常显示省份列表,选择省份后城市列表无变化啊,好像是少了城市的初始化吧 但是我不知道怎么添加 希望高手帮帮忙
没有分了 大家就行行好 义务献爱心了哈 谢谢
谢谢 ivws 确实好用了
那请问这是为什么呢?
刚才查了一下书,说是<!-- //->的作用是使不支持JavaScript的浏览器忽略脚本,但是,如果是支持JavaScript的浏览器还会忽略吗?不解诶。
感谢各位的回答,确实有收获,可是想知道这<!-- //->这个东西怎么会对代码效果有影响呢? 展开
2个回答
展开全部
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>New Document </title>
<script language="JavaScript" type="text/javascript">
var city=[
["北京","天津","上海","重庆"],
["南京","苏州","南通","常州"],
["福州","福安","龙岩","南平"],
["广州","潮阳","潮州","澄海"],
["兰州","白银","定西","敦煌"]
];
function getCity(){
var sltProvince=document.getElementById("province");
var sltCity=document.getElementById("city");
var provinceCity=city[sltProvince.selectedIndex-1];
sltCity.length=1;
for(var i=0;i<provinceCity.length;i++){
sltCity[i+1]=new Option(provinceCity[i],provinceCity[i]);
}
}
</script>
</head>
<body>
<form action="somepage.asp" name=theForm">
<select name="province" id="province" onchange="getCity()">
<option value="0">请选择所在省份</option>
<option value="直辖市">直辖市</option>
<option value="江苏省">江苏省</option>
<option value="福建省">福建省</option>
<option value="广东省">广东省</option>
<option value="甘肃省">甘肃省</option>
</select>
<select id="city" name="city">
<option value="0">请选择所在城市</option>
</select>
</form>
</body>
</html>
<html>
<head>
<title>New Document </title>
<script language="JavaScript" type="text/javascript">
var city=[
["北京","天津","上海","重庆"],
["南京","苏州","南通","常州"],
["福州","福安","龙岩","南平"],
["广州","潮阳","潮州","澄海"],
["兰州","白银","定西","敦煌"]
];
function getCity(){
var sltProvince=document.getElementById("province");
var sltCity=document.getElementById("city");
var provinceCity=city[sltProvince.selectedIndex-1];
sltCity.length=1;
for(var i=0;i<provinceCity.length;i++){
sltCity[i+1]=new Option(provinceCity[i],provinceCity[i]);
}
}
</script>
</head>
<body>
<form action="somepage.asp" name=theForm">
<select name="province" id="province" onchange="getCity()">
<option value="0">请选择所在省份</option>
<option value="直辖市">直辖市</option>
<option value="江苏省">江苏省</option>
<option value="福建省">福建省</option>
<option value="广东省">广东省</option>
<option value="甘肃省">甘肃省</option>
</select>
<select id="city" name="city">
<option value="0">请选择所在城市</option>
</select>
</form>
</body>
</html>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2010-04-10
展开全部
参考一下这个select联动
参考资料: http://www.blueidea.com/common/shoutbox/redir.asp?id=11685
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询