zww23
(zww23)
中级会员
 
一般会员
UID 53813
精华
0
积分 427
帖子 343
金钱 427 喜悦币
威望 0
人脉 0
阅读权限 30
注册 2004-11-24
状态 离线
|
帮忙修改其中的BUG(二级联动)
当选了1系列的后,再选2系列,那在第二级那里也会出现1系列的东西。
<?php <form enctype="multipart/form-data" action="" name="frm" method="post">
<select name="s1" onChange="redirec(document.frm.s1.options.selectedIndex)"> <option selected="selected">第一级</option> <option value="1">1系列</option> <option value="2">2系列</option> <option value="3">3系列</option> <option value="4">4系列</option> <option value="5">5系列</option> <option value="6">6系列</option> </select> <select name="s2"> <option selected="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[1][0]=new Option("1-1系列","1"); select2[1][1]=new Option("1-2系列","2"); select2[1][2]=new Option("1-3系列","3"); select2[1][3]=new Option("1-4系列","4"); select2[1][4]=new Option("1-5系列","5"); select2[1][5]=new Option("1-6系列","6");
select2[2][0]=new Option("2-1系列","7"); select2[2][1]=new Option("2-2系列","8"); select2[2][2]=new Option("2-3系列","9");
select2[3][0]=new Option("3-1系列","10"); select2[3][1]=new Option("3-2系列","11"); select2[3][2]=new Option("3-3系列","12"); select2[3][3]=new Option("3-4系列","13");
select2[4][0]=new Option("4-1系列","14");
select2[5][0]=new Option("5-1系列","15"); select2[5][1]=new Option("5-2系列","16"); select2[5][2]=new Option("5-3系列","17");
select2[6][0]=new Option("6-1系列","18"); select2[6][1]=new Option("6-2系列","19"); select2[6][2]=new Option("6-3系列","20"); select2[6][3]=new Option("6-4系列","21");
//联动函数 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> ?> [ 本帖最后由 zww23 于 2006-7-13 04:57 PM 编辑 ]
|
|