问题其实不复杂,但是你的代码写的让后面不易处理,父节点和子节点之间是相互独立的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涉及到定位问题
建议修改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涉及到定位问题
解决方案 »
- 大家帮忙看看
- 如何让文本域滚动条到最下边的时候,按钮可按
- 如何将被十六进制编码的汉字还原为可以正常浏览的汉字?
- 网易新闻评论效果是扎回事?
- 求给定一个日期,算出该日期在那个月第几周的函数
- 过滤标签,控制样式,这个问题该怎么解决 :(
- 【求助】在showModalDialog完成验证后如何返回主页面?
- 〖新手上路〗页面里只有一个<input ……>,怎么取其值作为参数传递啊???
- 怎么在下拉菜单项改变时,改变另一处的图片啊,大侠救命啊,在线等待!!!
- 如何关闭菜单栏、状态栏、地址栏和工具栏,谢谢!
- 能用javascript写代码实现插入数据到数据库的功能吗,怎么实现?在线等
- 父子窗口特难问题。。。。。好多分!
<%
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>
[email protected]
我也使用jsp,急需,谢谢
[email protected]
看了几个你的教程,希望能看到更多的!