急需解决的一个树形菜单问题

lingjiadong 2006-03-22 05:34:09
http://www.sunsd.com.cn/WebMain.asp?ID=2
这是我做的一个树形结构的菜单,是利用ASP生成的,只有一级和二级,现在问题是老板非要在打开的时候先缩起二级菜单,点了一级菜单后再出现.
我写的代码如下:
1.先用JS来判断
<script language="JavaScript">
function showhide(tab)
{
if (tab.style.display=='none')
{
tab.style.display='block';
}
else
{
tab.style.display='none';
}
}
</script>

2.table里加入onclick事件
<table width="156" border="0" cellpadding="2" cellspacing="1" height="76">
<%
set rs2 = server.createobject("adodb.recordset")
rs2.source = "select * from Deeptree where parentid=0 order by id "
rs2.open rs2.source,conn,1,1
if rs2.eof then response.write"<div align='center' font style='font-size:10pt;font-family: 宋体;color=green'><br><b>还没有产品分类!</b><br></div><br><br>"
while not rs2.eof
Pid=rs2("id")
%>

<tr><td width="18" height="24" align="right" >
<p align="center"><img height="12" src="images/t3.jpg"
width="12" /></td>
<td width="127"><a href="ProMain.asp?id=<%=rs2("id")%>" onclick="showhide(0)"><%=rs2("content")%></a></td>
</tr>
<tr><td height="9" align="right" colspan="2" >
<img height="5" src="images/xt.jpg"
width="149" /></td>
</tr>


<%
set rss = server.createobject("adodb.recordset")
rss.source = "select * from Deeptree where parentid="&Pid&""
rss.open rss.source,conn,1,1

while not rss.eof
%>
<tbody id="0" style="display:none">
<tr><td width="18" height="24" align="right"></td>

<td width="127"><img height="12" src="images/t3.jpg"
width="12" /> <a href="ProMain.asp?id=<%=rs2("id") & "-" & rss("id")%>"><%=rss("content")%></a></td>
</tr>
<tr><td width="145" height="14" align="right" colspan="2"><img height="5" src="images/xt.jpg"
width="149" /></td>

</tr>
</tbody>
<%
rss.movenext
wend
rss.close
set rss=nothing
%>
<%
'========
rs2.movenext
wend
rs2.close
set rs2=nothing
%>

</table>

但是达不到效果,我估计是因为我的<tbody>是在两层循环里,所以<tbody>的id重复了,但我不知道怎么办,请各位大哥大姐帮忙,谢谢了,我真的蛮急.
...全文
160 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
yjmaoo 2006-03-24
  • 打赏
  • 举报
回复
就是啊 我再送你20分,呵呵

还有个问题:我想要显示三层的树 但是第二层不能缩进,怎么回事 我修改了table 的width 也不行,代码如下:


<TABLE cellSpacing=0 cellPadding=0 width=158 align=center>
<TBODY>
<TR bgcolor="#999999">
<TD class=menu_title id=menuTitle1
onmouseover="this.className='menu_title2';" style="CURSOR: hand"
onclick=showsubmenu(14)
onmouseout="this.className='menu_title';"
background="Images/Left_1.gif" height=25><SPAN>管理aa</SPAN> </TD>
</TR>
<TR>
<TD id=submenu14>

<DIV style="WIDTH: 158px">
<TABLE cellSpacing=0 cellPadding=0 width=130 align=center>
<TBODY>
<TR>
<TD height=20>

<TABLE cellSpacing=0 cellPadding=0 width=100 align=center>
<TBODY>
<TR bgcolor="#999999">
<TD class=menu_title id=menuTitle1
onmouseover="this.className='menu_title2';" style="CURSOR: hand"
onclick=showsubmenu(3)
onmouseout="this.className='menu_title';"
height=25><SPAN>管理aa</SPAN> </TD>
</TR>
<TR>
<TD id=submenu3>
<DIV class=sec_menu style="WIDTH: 158px">
<TABLE cellSpacing=0 cellPadding=0 width=80 align=center>
<TBODY>
<TR>
<TD height=20 bgcolor="#CCCCCC">
增加项目
</TD></TR>
</TBODY></TABLE>
</DIV>
</TD></TR></TBODY></TABLE>

</TD></TR></TBODY></TABLE>
</DIV>
</TD></TR></TBODY></TABLE>
sky0120 2006-03-24
  • 打赏
  • 举报
回复
楼主记得结贴哦~ ^-^
yjmaoo 2006-03-24
  • 打赏
  • 举报
回复
非常感谢忍者鱼,呵呵
sky0120 2006-03-24
  • 打赏
  • 举报
回复
保存为asp文件,运行。你那个一样的道理,就用你那个id循环就行
sky0120 2006-03-24
  • 打赏
  • 举报
回复
有循环的:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<SCRIPT language=javascript1.2>
function showsubmenu(sid)
{
whichEl = eval("submenu" + sid);
if (whichEl.style.display == "none")
{
eval("submenu" + sid + ".style.display=\"\";");
}
else
{
eval("submenu" + sid + ".style.display=\"none\";");
}
}
</SCRIPT>
</head>
<table width=100% cellpadding=0 cellspacing=0 border=0 align=left>
<tr><td valign=top>
<table width=158 border="0" align=center cellpadding=0 cellspacing=0>
<tr>
<td width="319" height=42 valign=bottom> 
</td>
</tr>
</table>
<%
Dim i
For i=1 to 5
%>
<TABLE cellSpacing=0 cellPadding=0 width=158 align=center>
<TBODY>
<TR bgcolor="#999999">
<TD class=menu_title id=menuTitle1
onmouseover="this.className='menu_title2';" style="CURSOR: hand"
onclick=showsubmenu(<%=i%>)
onmouseout="this.className='menu_title';"
background="Images/Left_1.gif" height=25><SPAN>管理<%=i%></SPAN> </TD>
</TR>
<TR>
<TD id="submenu<%=i%>" style="display:none ">
<DIV class=sec_menu style="WIDTH: 158px">
<TABLE cellSpacing=0 cellPadding=0 width=130 align=center>
<TBODY>
<TR>
<TD height=20 bgcolor="#CCCCCC">
增加项目
</TD>
</TR>

</TBODY>
</TABLE>
</DIV>
<DIV style="WIDTH: 158px">
<TABLE cellSpacing=0 cellPadding=0 width=130 align=center>
<TBODY>
<TR>
<TD height=20></TD>
</TR>
</TBODY>
</TABLE>
</DIV>
</TD>
</TR>
</TBODY>
</TABLE>
<%next%>


</TD></TR></TBODY></TABLE>

</body>
</html>
sky0120 2006-03-24
  • 打赏
  • 举报
回复
收起来
<TD id=submenu14 style="display:none ">
yjmaoo 2006-03-24
  • 打赏
  • 举报
回复
我想请教忍者鱼,你在二楼放的代码,我应用到了我的系统里,非常感谢,但是有个问题,就是运行后子结点是展开的,怎样设置让子结点收起来呢?
lingjiadong 2006-03-22
  • 打赏
  • 举报
回复
非常感谢忍者鱼的支持,我按照你的代码改了一下,还是不行,具体效果你可以看
http://www.sunsd.com.cn/ProMain.asp?id=20
lingjiadong 2006-03-22
  • 打赏
  • 举报
回复
谢谢你的支持,你这一段是静态的,没有循环,那肯定好做,关键是现在我循环了以后ID号控制的问题,现在主要是可能ID号循环后重复了,希望有哪位高手能帮我把这个问题解决掉,最好是就在我的代码中改改,谢谢了
sky0120 2006-03-22
  • 打赏
  • 举报
回复
<table width="156" border="0" cellpadding="2" cellspacing="1" height="76">
<%
set rs2 = server.createobject("adodb.recordset")
rs2.source = "select * from Deeptree where parentid=0 order by id "
rs2.open rs2.source,conn,1,1
if rs2.eof then response.write"<div align='center' font style='font-size:10pt;font-family: 宋体;color=green'><br><b>还没有产品分类!</b><br></div><br><br>"
while not rs2.eof
Pid=rs2("id")
%>

<tr><td width="18" height="24" align="right" >
<p align="center"><img height="12" src="images/t3.jpg"
width="12" /></td>
<td width="127"><a href="ProMain.asp?id=<%=rs2("id")%>" onclick="showhide(0)"><%=rs2("content")%></a></td>
</tr>
<tr><td height="9" align="right" colspan="2" >
<img height="5" src="images/xt.jpg"
width="149" /></td>
</tr>


<%
set rss = server.createobject("adodb.recordset")
rss.source = "select * from Deeptree where parentid="&Pid&""
rss.open rss.source,conn,1,1
dim k
k=0
while not rss.eof
%>

<tbody id="<%=k%>" style="display:none">


<tr><td width="18" height="24" align="right"></td>

<td width="127"><img height="12" src="images/t3.jpg"
width="12" /> <a href="ProMain.asp?id=<%=rs2("id") & "-" & rss("id")%>"><%=rss("content")%></a></td>
</tr>
<tr><td width="145" height="14" align="right" colspan="2"><img height="5" src="images/xt.jpg"
width="149" /></td>

</tr>
</tbody>
<%
rss.movenext

k=k+1

wend
rss.close
set rss=nothing
%>
<%
'========
rs2.movenext
wend
rs2.close
set rs2=nothing
%>

</table>
sky0120 2006-03-22
  • 打赏
  • 举报
回复
把上面代码保存运行一下看看,希望能有帮助
sky0120 2006-03-22
  • 打赏
  • 举报
回复
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<SCRIPT language=javascript1.2>
function showsubmenu(sid)
{
whichEl = eval("submenu" + sid);
if (whichEl.style.display == "none")
{
eval("submenu" + sid + ".style.display=\"\";");
}
else
{
eval("submenu" + sid + ".style.display=\"none\";");
}
}
</SCRIPT>
</head>
<table width=100% cellpadding=0 cellspacing=0 border=0 align=left>
<tr><td valign=top>
<table width=158 border="0" align=center cellpadding=0 cellspacing=0>
<tr>
<td width="319" height=42 valign=bottom> 
</td>
</tr>
</table>

<TABLE cellSpacing=0 cellPadding=0 width=158 align=center>
<TBODY>
<TR bgcolor="#999999">
<TD class=menu_title id=menuTitle1
onmouseover="this.className='menu_title2';" style="CURSOR: hand"
onclick=showsubmenu(14)
onmouseout="this.className='menu_title';"
background="Images/Left_1.gif" height=25><SPAN>管理aa</SPAN> </TD>
</TR>
<TR>
<TD id=submenu14>
<DIV class=sec_menu style="WIDTH: 158px">
<TABLE cellSpacing=0 cellPadding=0 width=130 align=center>
<TBODY>
<TR>
<TD height=20 bgcolor="#CCCCCC">
增加项目
</TD>
</TR>

</TBODY>
</TABLE>
</DIV>
<DIV style="WIDTH: 158px">
<TABLE cellSpacing=0 cellPadding=0 width=130 align=center>
<TBODY>
<TR>
<TD height=20></TD>
</TR>
</TBODY>
</TABLE>
</DIV>
</TD>
</TR>
</TBODY>
</TABLE>


<TABLE cellSpacing=0 cellPadding=0 width=158 align=center>
<TBODY>
<TR bgcolor="#999999">
<TD class=menu_title id=menuTitle1
onmouseover="this.className='menu_title2';" style="CURSOR: hand"
onclick=showsubmenu(11) onmouseout="this.className='menu_title';"
background="Images/Left_1.gif" height=25><SPAN>管理bb</SPAN> </TD>
</TR>
<TR>
<TD id=submenu11>
<DIV class=sec_menu style="WIDTH: 158px">
<TABLE cellSpacing=0 cellPadding=0 width=130 align=center>
<TBODY>
<TR>
<TD height=20 bgcolor="#CCCCCC">管理管理
</TD></TR>
</TBODY>
</TABLE>
</DIV>
<DIV style="WIDTH: 158px">
<TABLE cellSpacing=0 cellPadding=0 width=130 align=center>
<TBODY>
<TR>
<TD height=20></TD></TR></TBODY></TABLE>
</DIV>
</TD></TR></TBODY></TABLE>

</TD></TR></TBODY></TABLE>

</body>
</html>

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧