喜悦国际村 
» 游客:  注册 | 登录 | 搜索 | 统计 | 帮助

RSS 订阅当前论坛  

喜悦证交所已经关闭

上一主题 下一主题
     
标题: 帮忙修改其中的BUG(二级联动)  
 
zww23 (zww23)
中级会员
Rank: 3Rank: 3
一般会员



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=0i<select1_leni++) 
{
 
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 编辑 ]
2006-7-13 04:56 PM#1
查看资料  Blog  发短消息  顶部
 
zjh00958
新手上路
Rank: 1



UID 74738
精华 0
积分 8
帖子 22
金钱 8 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2006-6-9
状态 离线
[推荐阅读] 帮忙看下这个问题,急!!
好像去掉php的代码就可以了,也就是去掉第一行和最后一行
2006-7-13 05:28 PM#2
查看资料  发短消息  顶部
 
lzh_dl
新手上路
Rank: 1



UID 75582
精华 0
积分 19
帖子 17
金钱 19 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2006-6-27
状态 离线
[推荐阅读] 正则问题请教高手
这个容易,是你在新定义option时,没有清掉原来的option;
改过的代码如下:
function redirec(x){

var temp = document.frm.s2;
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<select2[x].length;i++){
  temp.options=new Option(select2[x].text,select2[x].value);
}
temp.options[0].selected=true;

}
2006-7-13 09:17 PM#3
查看资料  Blog  发短消息  顶部
 
zww23 (zww23)
中级会员
Rank: 3Rank: 3
一般会员



UID 53813
精华 0
积分 427
帖子 343
金钱 427 喜悦币
威望 0
人脉 0
阅读权限 30
注册 2004-11-24
状态 离线
[推荐阅读] 直接在mysql里可以执行的语句,php怎么会报错
非常感谢!
2006-7-14 02:23 PM#4
查看资料  Blog  发短消息  顶部
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题 | 开通个人空间  


 




Powered by Discuz! 6.1.0  © 2001-2010 Comsenz Inc.
Processed in 0.028601 second(s), 6 queries

(冀ICP备05009913号) 管理员:sadly 邮箱/MSN: sadly@phpx.com QQ:824008(长隐) 清除 Cookies - - Archiver - WAP