日期:2014-05-17  浏览次数:20953 次

大家给看看这个二级联动js,怎么选了2,1也都出了,急用,希望大家给看看,本人在此谢过各位!!
代码如下:
<form   name= "frm ">
<select   name= "s1 "   onChange= "redirec(document.frm.s1.options.selectedIndex) ">
  <option   selected> 请选择类型 </option>
  <option   value= "1 "   > 1 </option>
  <option   value= "2 "> 2 </option>
</select>

<select   name= "s2 ">
  <option   value= "请选择 "   selected> 请选择相关信息 </option>
</select>
</form>

    <script   language= "javascript ">
//获取一级菜单长度
var   select1_len   =   document.frm.s1.options.length;
var   select2   =   new   Array(select1_len);

//把一级菜单都设为数组
for   (i=0;   i <select1_len;   i++)  
{
  select2[i]   =   new   Array();
}

//定义基本选项
select2[0][0]   =   new   Option( "请选择相关信息 ",   "   ");

select2[0][0]   =   new   Option( "相关信息 ",   "   ");
select2[1][0]   =   new   Option( "1 ",   "   ");
select2[1][1]   =   new   Option( "1 ",   "   ");
select2[1][2]   =   new   Option( "1 ",   "   ");
select2[1][3]   =   new   Option( "1   ",   "   ");
select2[1][4]   =   new   Option( "1 ",   "   ");
select2[1][5]   =   new   Option( "1 ",   "   ");
select2[1][6]   =   new   Option( "1 ",   "   ");
select2[1][7]   =   new   Option( "1 ", "   ");
select2[1][8]   =   new   Option( "1 ",   "   ");
select2[1][9]   =   new   Option( "1 ",   "   ");
select2[2][0]   =   new   Option( "2 ",   "   ");
select2[2][1]   =   new   Option( "2   ",   "   ");

//联动函数
function   redirec(x)
{
  var   temp   =   document.frm.s2;  
  for   (i=0;i <select2[x].length;i++)
  {
    temp.options[i]=new   Option(select2[x][i].text,select2[x][i].value);
  }
  temp.options[0].selected=true;

} </script>

------解决方案--------------------
<%
response.expires=-1
response.expiresabsolute=now()-1
response.cachecontrol= "no-cache "
%>
<form name= "frm ">
<select name= "s1 " onChange= "redirec(this.options[this.selectedIndex].value) ">
<option selected> 请选择类型 </option>
<option value= "1 "> 1 </option>
<option value= "2 "> 2 </option>
</select>

<select name= "s2 ">
<option value= "请选择 " selected> 请选择相关信息 </option>
</select>
</form>

<script language= "javascript ">
//获取一级菜单长度
var select1_len = document.frm.s1.options.length;
var select2