三级联动菜单的一个问题...

zhouqing2542 2008-11-24 01:50:50
我现在想做一个三级菜单 已经做出来 但是想加代码 却不行了.
我查询数据库把一级分类显示在一级菜单上.显示出来后点击一级分类出现相对应的二级分类.点击二级分类显示相对应的三级分类..大概就这个意思.所有分类都是能从后台添加. 并非简单的把所有分类打上就可以.关键在于从数据库读取数据然后显示在菜单上 比较麻烦 下边是我写的代码 但不能用. 希望各位帮忙看看!

这事js
// JavaScript Document
function showtable(tableid)
{
whichtable=eval("table"+tableid);
if(whichtable.style.display=="none")
{eval("table"+tableid+".style.display=\"\";");}
else
{eval("table"+tableid+".style.display=\"none\";");}
}


<%
dim lmid,lmid2
set rs=server.CreateObject("adodb.recordset")
set rs0=server.CreateObject("adodb.recordset")
set rs1=server.CreateObject("adodb.recordset")
%>
<table width="190" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="190" height="25" bgcolor="#6699CC"><table width="198" border="0" align="center" cellpadding="0" cellspacing="2" style="cursor:hand;" onClick="showtable(1)">
<%

rs.open "select * from oshow_lm ",conn,1,1
if not rs.eof then
while not rs.eof
%>

<tr>
<td width="14" height="25" align="center" valign="middle"><img src="images/collapsed.gif" width="11" height="11"></td>
<td width="178" valign="middle"><a href="show.asp?lmid=<%=rs("id")%>"><font color="#FFFFFF"><%=rs("lm")%></font></a></td>
</tr> <%
rs.MoveNext
wend
end if
rs.close
set rs=Nothing
%>
</table></td>
</tr>
<tr>
<td>

<table style="display:none;" id="table1" width="150" border="0" align="center" cellpadding="0" cellspacing="2" bgcolor="#EFEFEF">


<%

lmid=request.querystring("lmid")
set rs0=server.CreateObject("adodb.recordset")
rs0.open "select * from oshow_lm where lmid='"&lmid&"'",conn,1,1
if not rs0.eof then
while not rs0.eof
%> <tr>
<td width="15" height="20" align="center">
<table width="150" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="25" bgcolor="#6699CC">


<table width="150" border="0" align="center" cellpadding="0" cellspacing="2" style="cursor:hand;" onClick="showtable(2)">
<tr>
<td width="15" align="center" valign="middle"><img src="images/collapsed.gif" width="11" height="11"></td>
<td valign="middle"><a href="show.asp?lmid2=<%=rs0("id")%>"><font color="#FFFFFF"><%=rs0("lm2")%></font></a></td>
</tr>
</table>



</td>
</tr>
<tr>
<td><table style="display:none;" id="table2" width="150" border="0" align="center" cellpadding="0" cellspacing="2" bgcolor="#EFEFEF">
<%
lmid2=request.querystring("lmid2")
set rs1=server.CreateObject("adodb.recordset")
rs1.open "select * from oshow_lm where lmid='"&lmid2&"'",conn,1,1
if not rs1.eof then
while not rs1.eof
%>
<tr>

<td><%=rs1("lm3")%></td>
</tr> <%
rs1.MoveNext
wend
end if
rs1.close
set rs1=Nothing
%>
</table>


</td>
</tr> <%
rs0.MoveNext
wend
end if
rs0.close
set rs0=Nothing
%>

</table>
</td>
</tr>

</table></td>
</tr>
</table>
...全文
71 点赞 收藏 11
写回复
11 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
zhouqing2542 2008-11-25
我试试。。
回复
yjy84317 2008-11-24
三级菜单的话下面这个决对能有,代码你自已加
<style type="text/css">

#navigation, #navigation li ul {
list-style-type:none;
}
#navigation {
margin:20px;
}
#navigation li {
float:left;
text-align:center;
position:relative;
}
#navigation li a:link, #navigation li a:visited {
display:block;
text-decoration:none;
color:#000;
width:120px;
height:40px;
line-height:40px;
border:1px solid #fff;
border-width:1px 1px 0 0;
background:#c5dbf2;
padding-left:10px;
}
#navigation li a:hover {
color:#fff;
background:#2687eb;
}
#navigation li ul li a:hover {
color:#fff;
background:#6b839c;
}
#navigation li ul {
display:none;
position:absolute;
top:40px;
left:0;
margin-top:1px;
width:120px;
}
#navigation li ul li ul {
display:none;
position:absolute;
top:0px;
left:130px;
margin-top:0;
margin-left:1px;
width:120px;
}
</style>
<script type="text/javascript">
function displaySubMenu(li) {
var subMenu = li.getElementsByTagName("ul")[0];
subMenu.style.display = "block";
}
function hideSubMenu(li) {
var subMenu = li.getElementsByTagName("ul")[0];
subMenu.style.display = "none";
}
</script>
</head>
<body>
<ul id="navigation">

<li onmouseover="displaySubMenu(this)" onmouseout="hideSubMenu(this)">
<a href="#">栏目3</a>
<ul>
<li onmouseover="displaySubMenu(this)" onmouseout="hideSubMenu(this)">
<a href="#">栏目3->菜单1</a>
<ul>
<li><a href="#">菜单1->子菜单1</a></li>
<li><a href="#">菜单1->子菜单2</a></li>
<li><a href="#">菜单1->子菜单3</a></li>
<li><a href="#">菜单1->子菜单4</a></li>
</ul>
</li>


</ul>
</li>
</ul>
回复
yjy84317 2008-11-24
你是想做三级联动菜单,还是想做三级菜单?
回复
zhouqing2542 2008-11-24
关键是怎么做啊 我能试点方法都试了。实在是很郁闷。。各位在辛苦下了
回复
gmlwl 2008-11-24
用javascript就可以搞定,不用刷新

回复
zhouqing2542 2008-11-24
[Quote=引用 3 楼 layers2323 的回复:]
你要刷新的话,就提交到本页面,根据提交的参数不同,生成不同的菜单内容。
[/Quote] 可是我现在的代码就是按你这样说的做 可还是不显示..
回复
zhouqing2542 2008-11-24
楼上给的好像对我没用.不过也谢谢了.
回复
sy_binbin 2008-11-24

<script>
<!--
<%
'二级数据保存到数组
Dim count2,cityRS,citySQL
set cityRS=server.createobject("adodb.recordset")
citySQL="select * from sys_city"
cityRS.open citySQL,conn,1,1
%>
var subval2 = new Array();
//数组结构:一级根值,二级根值,二级显示值
<%
count2 = 0
do while not cityRS.eof
%>
subval2[<%=count2%>] = new Array('<%=cityRS("provinceid")%>','<%=cityRS("id")%>','<%=cityRS("cityname")%>')
<%
count2 = count2 + 1
cityRS.movenext
loop
cityRS.close
%>
<%
'三级数据保存到数组
Dim count3,townRS,townSQL
set townRS=server.createobject("adodb.recordset")
townSQL="select * from sys_town"
townRS.open townSQL,conn,1,1
%>
var subval3 = new Array();
//数组结构:二级根值,三级根值,三级显示值
<%
count3 = 0
do while not townRS.eof
%>
subval3[<%=count3%>] = new Array('<%=townRS("cityid")%>','<%=townRS("ID")%>','<%=townRS("townname")%>')
<%
count3 = count3 + 1
townRS.movenext
loop
townRS.close
%>
function changeselect1(locationid)
{
document.form1.cityID.length = 0;
document.form1.cityID.options[0] = new Option('请选择城市','');
document.form1.townID.length = 0;
document.form1.townID.options[0] = new Option('请选择城区','');
for (i=0; i<subval2.length; i++)
{
if (subval2[i][0] == locationid)
{document.form1.cityID.options[document.form1.cityID.length] = new Option(subval2[i][2],subval2[i][1]);}
}
}

function changeselect2(locationid)
{
document.form1.townID.length = 0;
document.form1.townID.options[0] = new Option('请选择城区','');
for (i=0; i<subval3.length; i++)
{
if (subval3[i][0] == locationid)
{document.form1.townID.options[document.form1.townID.length] = new Option(subval3[i][2],subval3[i][1]);}
}
}
//-->
<form id="form1" name="form1" method="post" action="">
<%
Dim count1,provinceRS,provinceSQL
set provinceRS=server.createobject("adodb.recordset")
provinceSQL="select * from sys_province order by orderfield"
provinceRS.open provinceSQL,conn,1,1
%>

<select name="provinceID" id="provinceID" onChange="changeselect1(this.value)">
<option value="">请选择省份</option>
<%
do while not provinceRS.eof
response.Write "<option value="&provinceRS("ID")&">"&provinceRS("provincename")&"</option>"
provinceRS.movenext
loop
provinceRS.close
set provinceRS = nothing
%>
</select>
<select name="cityID" id="cityID" onChange="changeselect2(this.value)">
<option value="">请选择城市</option>
</select>
<select name="townID" id="townID">
<option value="">请选择城区</option>
</select>
</form>
</script>
回复
layers2323 2008-11-24
你要刷新的话,就提交到本页面,根据提交的参数不同,生成不同的菜单内容。
回复
zhouqing2542 2008-11-24
得用AJAX 还有别的方法吗.如果能刷新的话 如何做.
回复
yanniu008 2008-11-24
这个你去网上搜一下 “无刷新 三级菜单”
要用到AJAX
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2008-11-24 01:50
社区公告
暂无公告