两个下拉框

mimihuhu 2004-05-08 01:56:58
我想得到两个下拉框,如前面一个是省,后面是省的所有市,前面一个下拉框选择改变时,后面的内容也改变,最好存成二维数组,要javascript
...全文
53 6 点赞 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
52juanjuan 2004-05-08
通过关联二级下拉菜单来实现就可以了
  • 打赏
  • 举报
回复
wanghr100 2004-05-08
阿信那个不错.

<script language = "JavaScript">
sall=new Array();
sall[0]=new Array("泉州","1","1");
sall[1]=new Array("厦门","1","2");
sall[2]=new Array("福州","1","3");
sall[3]=new Array("石狮","1","4");
sall[4]=new Array("武汉","2","5");
sall[5]=new Array("沙市","2","6");
sall[6]=new Array("孝感","2","7");
sall[7]=new Array("信阳","3","8");
sall[8]=new Array("郑州","3","9");
sall[9]=new Array("南阳","3","10");
function changeselect(selvalue)
{
document.myform.Nclassid.length=0;
var selvalue=selvalue;
var i;
for(i=0;i<sall.length;i++)
{
if(sall[i][1]==selvalue)
{
var newOption1=new Option(sall[i][0],sall[i][2]);
document.all.Nclassid.add(newOption1);
}
}
}
</script>
<form method="post" name="myform" action="ru_query.asp">
<select name="classid" onChange="changeselect(document.myform.classid.options[document.myform.classid.selectedIndex].value)" size="1">
<option selected value="">未指定条件</option>
<option value='1'>福建省</option>
<option value='2'>湖北省</option>
<option value='3'>河南省</option>
</select>
<select name="Nclassid">
<option selected value="">未指定</option>
</select>
  • 打赏
  • 举报
回复
rootcn 2004-05-08
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>select</title>
<script language="javascript">
var data = new Array(2);
var data2 = new Array(2);
data2[0] = 'province1';
data2[1] = 'province2';
data[0] = new Array(3);
data[1] = new Array(4);
data[2] = new Array(2);
data[0][0] = 'city11';
data[0][1] = 'city12';
data[0][2] = 'city13';
data[1][0] = 'city21';
data[1][1] = 'city22';
data[1][2] = 'city23';
data[1][3] = 'city24';
function init() {
var s1 = '<select name="id11" id ="d11" onChange="setdata(this.value);">';
for (var j = 0;j < data2.length ;j++) {
s1 = s1 + '<option value="' + (j + 1) + '">' + data2[j] + '</option>';
}
s1 = s1 + '</select>';

eval('id1').innerHTML = s1;

setdata(1);
}

function setdata(idNumber) {
var id = eval('id2');
var idNumber = idNumber - 1;
var cd = '<select name="id' + idNumber + '1" id ="id' + idNumber + '1">';
cd = cd + '<option selected>' + data[idNumber][0] + '</option>';
for (var i = 1;i<data[idNumber].length;i++)
cd = cd + '<option>' + data[idNumber][i] + '</option>'
cd = cd + '</select>';
id.innerHTML = cd;
}
</script>
</head>

<body>
<span id="id1">
<select name="id11" id="d1" onChange="setdata(this.value);">
</select>
</span>
<span id="id2">
<select name="id21" id="id21">
</select>
</span>
<script language="javascript">
init();
</script>
</body>
</html>

--------------------------------------
IE 6 下测试通过
  • 打赏
  • 举报
回复
mimihuhu 2004-05-08
哦,表达错误,我只是举例子,并不是要省市的下拉框,实际是想得到父类、子类的下拉框,因为内容是数据库动态添加的,和你给的例子有区别
  • 打赏
  • 举报
回复
deleteall8 2004-05-08
http://fason.nease.net/samples/bigarea/
  • 打赏
  • 举报
回复
fason 2004-05-08
http://fason.nease.net/samples/area/area.htm
  • 打赏
  • 举报
回复
相关推荐
发帖
JavaScript
加入

8.5w+

社区成员

Web 开发 JavaScript
申请成为版主
帖子事件
创建了帖子
2004-05-08 01:56
社区公告
暂无公告