关于页面中两个SELECT联动的问题
1个回答
展开全部
这个是我以前帮别人写的,你参考下吧。
<SCRIPT language = "JavaScript">
var onecount1;
onecount1=0;
subcat = new Array();
subcat[0] = new Array("手机","pho","63"); //注意逗手机地后面这个"pho" 那是代表你从表单中提取的value
subcat[1] = new Array("电话传真机","pho","64"); //同上
subcat[2] = new Array("sim卡","card","66"); //注意逗sim卡地后面这个"card" 那是代表你从表单中提取的value
subcat[3] = new Array("IC/IP卡","card","67"); //同上
onecount1=4;
function changelocation(locationid)
{
document.myform.diqu2.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount1; i++)
{
if (subcat[i][1] == locationid)
{
document.myform.diqu2.options[document.myform.diqu2.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
</SCRIPT>
<form action="" name="myform" method="POST">
<SELECT name="diqu1" onChange="changelocation(document.myform.diqu1.options[document.myform.diqu1.selectedIndex].value)" size="1">
<OPTION selected value="0">信息类别</OPTION>
<OPTION value="pho">电话类型</OPTION>
<OPTION value="card">电话卡</OPTION>>
</SELECT> <SELECT name="diqu2">
<OPTION selected value="0">二级分类</OPTION>
</SELECT>
</form>
<SCRIPT language = "JavaScript">
var onecount1;
onecount1=0;
subcat = new Array();
subcat[0] = new Array("手机","pho","63"); //注意逗手机地后面这个"pho" 那是代表你从表单中提取的value
subcat[1] = new Array("电话传真机","pho","64"); //同上
subcat[2] = new Array("sim卡","card","66"); //注意逗sim卡地后面这个"card" 那是代表你从表单中提取的value
subcat[3] = new Array("IC/IP卡","card","67"); //同上
onecount1=4;
function changelocation(locationid)
{
document.myform.diqu2.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount1; i++)
{
if (subcat[i][1] == locationid)
{
document.myform.diqu2.options[document.myform.diqu2.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
</SCRIPT>
<form action="" name="myform" method="POST">
<SELECT name="diqu1" onChange="changelocation(document.myform.diqu1.options[document.myform.diqu1.selectedIndex].value)" size="1">
<OPTION selected value="0">信息类别</OPTION>
<OPTION value="pho">电话类型</OPTION>
<OPTION value="card">电话卡</OPTION>>
</SELECT> <SELECT name="diqu2">
<OPTION selected value="0">二级分类</OPTION>
</SELECT>
</form>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询