各位好,我现在有这么一个级联下拉菜单组:
<table>
     <tr id="tr">
       <td>
         <select name="aa1" id="aa1" onChange="changelocation(document.form1.aa1.options[document.form1.aa1.selectedIndex].value)">         </select>         <select name="aa2" id="aa2">         </select>
       <td>
     </tr>
.
.
.
.     <tr id="tr">
       <td>
         <select name="aa1" id="aa1" onChange="changelocation(document.form1.aa1.options[document.form1.aa1.selectedIndex].value)">         </select>         <select name="aa2" id="aa2">         </select>
       <td>
     </tr>
</table>function changelocation(id)
    {
    document.form1.district.length = 0; 
 
    var id=id;
    var i;
    //document.form1.aa2.options[0] = new Option('选择二级分类','');
    for (i=0;i < onecount; i++)
        {
            if (subcat[i][1] == id)
            { 
                document.form1.district.options[document.form1.aa2.length] = new Option(subcat[i][0], subcat[i][2]);
            }        
        }
        
    }  
aa1与aa2是级联菜单,aa1改变的时候从一个数组里面取值来生成aa2现在的问题是:我通过javascript添加<tr></tr>生成了很多一样的行,也就是说所有select的name都相同所以在有多个的时候,
onChange="changelocation(document.form1.aa1.options[document.form1.aa1.selectedIndex].value)" 这个就报错了,我想是有多个的时候这就是一个下拉菜单组了,所以出错怎么确定当前操作的菜单是哪个呢?对应的动作由哪个下拉执行??表述不是很清楚,就大概这个意思了
请问怎么解决?

解决方案 »

  1.   

    解决办法很多啊
    可以给很多的ID,每个都不同
    可以用相同的name,在级联的时候,查找源select在同名数组中的index,就是另一个的index了
    可以用一起成熟的代码,把两个绑定
      

  2.   

    你好,怎么查找当前select在同名数组中的index?
      

  3.   

    楼上的你好,目前还有一点小问题,
    我现在传了两个参数进来,后面这个是当前级联下拉菜单在菜单组中的序号,但是发现只有在多个的时候才正常,一个的时候反而不正常了。是不是因为只有一个的时候不是一个数组,不能用序号标识?
    function changelocation(id,index)
        {
       document.form1.district[index].length = 0; 
        
        var id=id;
        var i;
       //document.form1.district.options[0] = new Option('选择二级分类','');
        for (i=0;i < onecount; i++)
            {
                if (subcat[i][1] == id)
                { //alert("cc"+index);
                    document.form1.district[index].options[document.form1.district[index].length] = new Option(subcat[i][0], subcat[i][2]);
                }        
            }
            
        } 
      

  4.   

    用document.getElementsByName("name");返回数组如果不能用,就判断一下