求三级省 市 区的级联菜单的源码,要求菜单内容数据库读取 高分有的请发[email protected]
包括,表结构,页面部分,等全部代码,谢谢啊,本人着急用

解决方案 »

  1.   

    页面 jsp 
    所有数据从数据库中读取
      

  2.   

    你可以参考我的实现方法:
    1.JavaScript方法:   
       //当局下拉列表的值确定的时候,那么处下拉列表的值也随之变化
            function juChange(parentId){
              //当局下拉列表的值变化的时候,将处下拉列表的值进行清空,避免出现处和下拉列表的值重复的情况
              document.formAct.chu.length=0;
              //得到处记录集的所有个数,并将其赋给js变量count
              var count = <%=chuList.size()%>;
              //定义一个js数组,将所有处站点的数据集逐一赋给js数组
              var selChu = new Array();
              <%
              for(int i=0;i<chuList.size();i++){
                 int id = (((Dept)chuList.get(i)).getId()).intValue();
                 String name = ((Dept)chuList.get(i)).getName();
                 Integer pid = ((Dept)chuList.get(i)).getParentid();
                 System.out.println("id="+id+" name="+name+" pid="+pid);
                 %>
                 selChu[<%=i+1%>]=new Array("<%=id%>","<%=name%>","<%=pid%>");
                 <%
              }         
              %>
              selChu[0]=new Array("","",parentId);
              for(var i=0;i<count+1;i++){
                 if(selChu[i][2]==parentId){
                   document.formAct.chu.options[document.formAct.chu.length] = 
                      new Option(selChu[i][1],selChu[i][0]);
                 }
               }
            }
    2:在下拉列表中添加如下方法:
    <select name="ju" style="width:220 "
                           onchange="juChange(document.formAct.ju.options[document.formAct.ju.selectedIndex].value)">
      

  3.   

    至于数据,随便你怎么取,因为你是从数据库中查询出来的,不过一般的都是用list来表示的;因为javascript的变量不能传给java,而java的变量确可以传给javascript,所以取值的时候,就全部取出来,然后利用传进来的参数值进行过滤,再把过滤之后的结果集传给下一个下拉列表
      

  4.   

    既然要求有联动的,那么就建在一张表里面,这样好控制
    id    name     parentid     
    有这三个最主要的字段就可以了,然后第一级的parentid为null,因为它没有父类,至于第二级,第三级的,都有父类,这样就可以控制住了
    你可以参考以下的这篇文章:
    http://dev2dev.bea.com.cn/bbs/thread.jspa?
    forumID=121&threadID=37006&messageID=219585#219585
      

  5.   

    //=================公司类方法===================//
    public String getDrop(String compid,String dataid) throws Exception{
          if(str.IsEmpty(dataid) )
            dataid="AAA";
          Compid  com[]=this.readAll(compid,dataid);
          StringBuffer bf = new StringBuffer();
          if(com.length > 0){
               for(int i=0;i<com.length ;i++){
                 if(dataid.equals(com[i].getBh()) )
                   bf.append("<option value=" + com[i].getID()  + " selected >" + com[i].getName() + "</option>") ;
                 else
                   bf.append("<option value=" + com[i].getID()  + ">" + com[i].getName() + "</option>") ;
               }
             }
        return bf.toString();
        }
     //=================部门类方法同上===================////====================页面调用=====================//   Compid com = new Compid();
       Deptid dep = new Deptid();
       Deptid [] depAll=bm.readAll("","");          <select name="deptid" style="width:120px">
               <option value="">所有公司
                <%=com.getDrop(compid,deptid)%>
              </select>          <select name="deptid" style="width:120px">
               <option value="">所有部门
                <%=dep.getDrop(compid,deptid)%>
              </select>
    <script language=javascript>
     var bm= new Array();
     <%if(depAll.length>0){
         for(int i=0;i<depAll.length;i++){%>
         bm[<%=i%>] = new Array("<%=depAll[i].getCom()%>","<%=depAll[i].getID()%>","<%=depAll[i].getName()%>");
      <%}}%>
     function setBm(){
      document.form_com_dep.deptid.length = 0; 
      document.form_com_dep.deptid.options[document.form_com_dep.deptid.length] = new Option("所有部门","");
      var comp = document.form_com_dep.compid.value ;
      var i=0;
      for (i=0;i < <%=depAll.length%> ; i++)  {
          if (bm[i][0] == comp ) {
             document.form_com_dep.deptid.options[document.form_com_dep.deptid.length] = new Option(bm[i][2], bm[i][1]);
                 }        
         }
     }
    </script>