问题其实不复杂,但是你的代码写的让后面不易处理,父节点和子节点之间是相互独立的div,id也没有什么规律性,递归很难实现。
建议修改asp程序,使得生成后的目录树代码是这种格式
<div id="d01">
  <div id="d0101">
    <div id="d010101">
    </div>
    <div id="d010102">
    </div>
  </div>
  <div id="d0102">
  </div>
</div>
这样,只要隐藏d01,它所包含的div都被隐藏起来另外还建议使用table来做,div涉及到定位问题

解决方案 »

  1.   

    <!-- #include file="../Function/OpenDataBase.asp" -->
    <%
    Function GetConn
    'On Error Resume Next
    'Dim Conn
    'Set Conn = Server.CreateObject("ADODB.Connection")
    'Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("teacher.MDB")
    'Conn.Open
    Set GetConn = Conn
    End FunctionFunction WriteTree(ParentID,Prefix)
    Dim Rs, ThisID, SQL, ImgPath, ImgPath2, ImgPath3, HasSubItem, IsEnd, ThisPrefix
    Set Rs = Server.CreateObject("ADODB.RecordSet")
    SQL = "Select * From tbl_Tree Where I_Rank=" & ParentID
    Rs.Open SQL, GetConn, 1
    For i = 1 To Rs.RecordCount
    HasSubItem = GetConn.Execute("Select Count(*) From tbl_Tree Where I_Rank=" & Rs("I_RecordID"))(0)
    If i = Rs.RecordCount Then  '最后一个节点
    If HasSubItem > 0 Then  '有子节点
    ImgPath = "Lessons/TreeImages/Line_plastnode.gif"
    ImgPath2 = "Lessons/TreeImages/Line_mlastnode.gif"
    ImgPath3 = "Lessons/TreeImages/OpenediDefFolder.gif"
    Else  '没有子节点
    ImgPath = "Lessons/TreeImages/Line_lastnode.gif"
    ImgPath2 = "Lessons/TreeImages/Line_lastnode.gif"
    ImgPath3 = "Lessons/TreeImages/iText.gif"
    End If
    IsEnd = True
    Else '非最后一个节点
    If HasSubItem > 0 Then  '有子节点
    ImgPath = "Lessons/TreeImages/Line_pnode.gif"
    ImgPath2 = "Lessons/TreeImages/Line_mnode.gif"
    ImgPath3 = "Lessons/TreeImages/OpenediDefFolder.gif"
    Else  '没有子节点
    ImgPath = "Lessons/TreeImages/Line_node.gif"
    ImgPath2 = "Lessons/TreeImages/Line_node.gif"
    ImgPath3 = "Lessons/TreeImages/iText.gif"
    End If
    IsEnd = False
    End If
    If Prefix = "" And i = 1 Then ImgPath = "Lessons/TreeImages/School.gif" '第一个节点使用特殊图标
    If IsEnd Then  '最后一个节点
    ThisPrefix = Prefix & "<img height=16 width=16 src=""Lessons/TreeImages/Node_blank.gif"">"
    Else '非最后一个节点
    ThisPrefix = Prefix & "<img height=16 width=16 src=""Lessons/TreeImages/Line_vertline.gif"">"
    End If
    If HasSubItem > 0 Then  '有子节点
    If Rs("B_Link") Then  '有链接
    Response.Write Prefix & "<span style=""cursor:hand;""><img src=""" & ImgPath & """><img src=""" & ImgPath2 & """ style=""display:none""><img height=16 width=16 src=""" & ImgPath3 & """><a href=""" & Rs("C_Link") & """><span style=""border:#FFFFFF 1 solid;"" onmouseover=""this.style.backgroundColor='#DDDDDD';this.style.borderColor='#999999';"" onmouseout=""this.style.backgroundColor='';this.style.borderColor='#FFFFFF';"">" & Rs("C_Title") & "</span></a></span><br>"
    Else  '没有链接
    Response.Write Prefix & "<span style=""cursor:hand;"" onclick=""clickItem(this);""><img src=""" & ImgPath & """><img src=""" & ImgPath2 & """ style=""display:none""><img height=16 width=16 src=""" & ImgPath3 & """><span style=""border:#FFFFFF 1 solid;"" onmouseover=""this.style.backgroundColor='#DDDDDD';this.style.borderColor='#999999';"" onmouseout=""this.style.backgroundColor='';this.style.borderColor='#FFFFFF';"">" & Rs("C_Title") & "</span></span><br>"
    End If
    Response.Write "<span style=""display:none;"">"
    Call WriteTree(Rs("I_RecordID"),ThisPrefix)  '递归调用
    Response.Write "</span>"
    Else  '没有子节点
    If Rs("B_Link") Then  '有链接
    Response.Write Prefix & "<span style=""cursor:hand;""><img height=16 src=""" & ImgPath & """><img src=""" & ImgPath2 & """ style=""display:none""><img height=16 width=16 src=""" & ImgPath3 & """><a href=""" & Rs("C_Link") & """><span style=""border:#FFFFFF 1 solid;"" onmouseover=""this.style.backgroundColor='#DDDDDD';this.style.borderColor='#999999';"" onmouseout=""this.style.backgroundColor='';this.style.borderColor='#FFFFFF';"">" & Rs("C_Title") & "</span></a></span><br>"
    Else  '没有链接
    Response.Write Prefix & "<span style=""cursor:hand;""><img height=16 src=""" & ImgPath & """><img src=""" & ImgPath2 & """ style=""display:none""><img height=16 width=16 src=""" & ImgPath3 & """><span style=""border:#FFFFFF 1 solid;"" onmouseover=""this.style.backgroundColor='#DDDDDD';this.style.borderColor='#999999';"" onmouseout=""this.style.backgroundColor='';this.style.borderColor='#FFFFFF';"">" & Rs("C_Title") & "</span></span><br>"
    End If
    End If
    Rs.MoveNext
    Next
    End Function
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE>TreeMenu Test</TITLE>
    <base href="http://hyg:88/Test/treeproblem/">
    <META NAME="Generator" CONTENT="EditPlus">
    <script language="JavaScript">
    function clickItem(obj)
    {
    var srcobj = obj.nextSibling.nextSibling;
    if(srcobj.style.display == "none")
    {
    srcobj.style.display = "";
    }
    else
    {
    srcobj.style.display = "none";
    }
    if(obj.children[0].style.display == "none")
    {
    obj.children[0].style.display = "";
    obj.children[1].style.display = "none";
    }
    else
    {
    obj.children[0].style.display = "none";
    obj.children[1].style.display = "";
    }
    }
    </script>
    </HEAD><BODY>
    <%Call WriteTree(0,"")%>
    </BODY>
    </HTML>
      

  2.   

    hehe,我这里有一个完整的无限节点,无限层次的JavaScript树,而且可以选择是否使用checkbox,看你要不要:)在我公司的使用中是使用JavaBean和Servlet+Jsp的方法实现后台数据库的读取的。如果你要给我留言吧。
      

  3.   

    超级马桶,我要!
    [email protected]
    我也使用jsp,急需,谢谢
      

  4.   

    楼上的几位,如果不急的话可以稍微等个几天,估计在元旦前后我会详细的总结一下在DHTML中Tree的编写和使用。到时候会有详细的文档和范例程序。
      

  5.   

    能给我一份吗?学习一下
    [email protected]
      

  6.   

    supertoto(超级马桶)
    看了几个你的教程,希望能看到更多的!