jsp页面的2级联动菜单,内容是从后台数据库里查出来的。
想要用脚本来实现菜单的联动,希望大家能给个简单实用的脚本外加说明!!!
谢谢

解决方案 »

  1.   

    <script type="text/javascript" language="javascript">
          var subindusid=new Array(""
            <logic:present name="subindus">            //subindus是个list的第二级数据
                <logic:iterate id="sindus" name="subindus">
                    ,"<bean:write name="sindus" property="industryId"/>"     // id
                </logic:iterate>
            </logic:present>
                  );
          var subindusna=new Array(""
            <logic:present name="subindus">
                <logic:iterate id="sindus" name="subindus">
                    ,"<bean:write name="sindus" property="industryName"/>"    // name
                </logic:iterate>
            </logic:present>
                  );
          function onsel(){
              var mainid=""+myform.mainindustry.value;
              var psel=myform.subindustry.options;
              for(i=psel.length-1;i>0;i--){
                  myform.subindustry.remove(i);
              }
              if(mainid=='0')
              return;
              for(j=1;j<subindusid.length;j++){
                  var tl=subindusid[j].length-2;
                  var tst=subindusid[j].substring(0,tl);
                  if(tst==mainid){
                      opt=document.createElement ("OPTION");
                      opt.value=subindusid[j];
                      opt.text=subindusna[j];
                      myform.subindustry.add(opt);              }
              }
          }
      </script>                         <tr>
                                 <td> 主行业: </td>
                                 <td>
                                     <select name="mainindustry" onchange="onsel();">
                                         <option value="0" selected><bean:message key="mainindustry.default"/></option>
                                         <logic:present name="allmainindus">
                                             <logic:iterate id="indus" name="allmainindus">
                                                <option value="<bean:write name="indus" property="industryId"/>"><bean:write name="indus" property="industryName"/></option>
                                             </logic:iterate>
                                         </logic:present>
                                     </select>
                                 </td>
                             </tr>
                            <tr>
                                <td>  二级行业  </td>
                                <td>
                                    <select name="subindustry">
                                        <option value="0" selected><bean:message key="subindustry.default"/></option>
                                    </select>
                                </td>
                            </tr>
      

  2.   

    用了struts的标签 不知道你会不会
      

  3.   

    我正是用的struts的标签。
    有些地方不太理解,能把你QQ给我吗?
      

  4.   

    <script type="text/javascript" language="javascript">
          var id=new Array(""
            <logic:notEmpty name="type">            //type是个list的第二级数据
                <logic:iterate id="ty" name="type">
                    ,"<bean:write name="ty" property="personaltypeCategoryId"/>"     // id
                </logic:iterate>
            </logic:notEmpty>
                  );
          var title=new Array(""
            <logic:notEmpty name="type">
                <logic:iterate id="ty" name="type">
                    ,"<bean:write name="ty" property="personaltypeTitle"/>"    // title
                </logic:iterate>
            </logic:notEmpty>
                  );
          function onsel(){
              var mainid=""+myform.category.value;
              var psel=myform.type.options;
              for(i=psel.length-1;i>0;i--){
                  myform.type.remove(i);
              }
              if(mainid=='0')
              return;
              for(j=1;j<id.length;j++){
                  var tl=id[j].length-2;
                  var tst=id[j].substring(0,tl);
                  if(tst==mainid){
                      opt=document.createElement ("option");
                      opt.value=id[j];
                      opt.text=title[j];
                      myform.type.add(opt);              }
              }
          }
      </script>
    </head><body>
    <form method="POST" name="myform">
    <table>
    <tr>
    <td>
    主行业:
    </td>
    <td>
    <select name="category" onchange="onsel();">
    <option value="0" selected>
    1111
    </option>
    <logic:notEmpty name="category">
    <logic:iterate id="ca" name="category">
    <option value="<bean:write name="ca" property="personalCategoryId"/>">
    <bean:write name="ca" property="personalCategoryTitle" />
    </option>
    </logic:iterate>
    </logic:notEmpty>
    </select>
    </td>
    </tr>
    <tr>
    <td>
    二级行业
    </td>
    <td>
    <select name="type">
    <option value="0" selected>
    2222
    </option>
    </select>
    </td>
    </tr>
    </table>
    </form>
    </body>不灵啊,那里不对劲呢??
      

  5.   

    这里放qq麻烦,你把你的qq或者msn发我邮箱 [email protected]