asp 多级菜单(美化)

该博客主要围绕ASP实现菜单功能展开。定义了菜单表结构,通过SQL查询获取菜单数据并存储到数组中。利用ASP代码实现菜单的递归输出,同时使用CSS控制菜单样式,如不同层级菜单的背景颜色、高度等,还包含管理首页和退出管理等链接。
部署运行你感兴趣的模型镜像

表结构

id                       int              

MenuName        nvarchar               50

MenuUrl            nvarchar               255

ParentID            int

Step                   int

<!--#include file="../inc/conndb.asp"-->
<%
'==============================================
'                     数据源
'==============================================
dim rs,sql,rscount
set rs=server.CreateObject("ADODB.recordset")
sql="select * from menu order by id asc"
rs.open sql,conn,1,1
rscount=rs.recordcount
'==============================================
'     将数据存入数组
'==============================================
dim menu(100,3) '需要按记录条数改动
dim ItemString
for i=0 to rscount-1
 if rs.eof or rs.bof then exit for
 if trim(rs("MenuUrl"))<>"" then
 ItemString="<a href='"&rs("MenuUrl")&"' target='main'>"&rs("MenuName")&"</a>"
 else
 ItemString=rs("MenuName")
 end if
 menu(i,0)=rs("ID")
 menu(i,1)=ItemString
 menu(i,2)=rs("ParentID")
 menu(i,3)=rs("Step")
 rs.movenext
next

'==============================================
'     实现Menu
'==============================================
dim css '样式
dim ourstr,stepinfo
sub GetMenu(parentid)
 for j=0 to ubound(menu,1)
  if parentid=menu(j,2) then
  stepinfo=menu(j,3)
  css="step"&stepinfo
  
  '控制输出样式
  if cint(stepinfo)=1 then
   outstr="<div class="""&css&""" onmouseover=""this.style.backgroundColor='#DEE7FF';""  onmouseout=""this.style.backgroundColor='#F1F1F1'"" align='left'><img src='../pic/bullet.gif'>"&menu(j,1)&"</div>"
  elseif cint(stepinfo)=2 then
   outstr="<div class="""&css&""" onmouseover=""this.style.backgroundColor='#DEE7FF';""  onmouseout=""this.style.backgroundColor='#F1F1F1'"" align='left'>"&menu(j,1)&"</div>"
  else
   outstr="<div class="""&css&""" align='left'>"&menu(j,1)&"</div>"
  end if
  response.Write(outstr)
  if menu(j,0)<>"" then

   GetMenu menu(j,0)
  end if
  end if
 next
 
end sub
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>menu</title>
<style type="text/css">
<!--
body  { margin:0px; font:normal 12px 宋体;
SCROLLBAR-FACE-COLOR: #799AE1; SCROLLBAR-HIGHLIGHT-COLOR: #799AE1;
SCROLLBAR-SHADOW-COLOR: #799AE1; SCROLLBAR-DARKSHADOW-COLOR: #799AE1;
SCROLLBAR-3DLIGHT-COLOR: #799AE1; SCROLLBAR-ARROW-COLOR: #FFFFFF;
SCROLLBAR-TRACK-COLOR: #AABFEC;
}
div.step0 {
 background-color: #037BC2;
 height: 18px;
 width: 150px;
 font-weight: bold;
 color: #FFFFFF;
 text-align: center;
}
div.step1 {
 height: 18px;
 cursor: hand;
 padding-left: 10px;
}
div.step2 {
 height: 18px;
 cursor: hand;
 padding-left: 40px;
}
div {
 font-size: 12px;
}
table{
 font-size: 12px;
}
a:link {
 color: #002084;
 text-decoration: none;
}
a:visited {
 text-decoration: none;
 color: #002084;
}
a:hover {
 text-decoration: underline;
}
a:active {
 text-decoration: underline;
}
.kuang {
 border: 1px solid #5582D2;
 background-color: #f1f1f1;
}
-->
</style>
</head>
<body bgcolor="#8CAAE6">
  <br>
<table width="160"  border="0" align="center" cellpadding="0" cellspacing="0" class="kuang">
    <tr>
      <td height="8" align="center" bgcolor="#002F5E"><img src="../pic/dot.gif" width="1" height="1"></td>
    </tr>
    <tr>
      <td height="25" align="center"><span class="menu_title"><a href="main.asp" target=main><b>管理首页</b></a> | <a href="../login/logout.asp" target=_top><b>退出管理</b></a><a href="menu_list.asp" target=main><b></b></a></span></td>
    </tr>
    <tr>
      <td align="center"><% call GetMenu(0)%></td>
    </tr>
  </table>
  <br>
 </body>
</html>


<%
'==============================================
'???????????????????? 数据源
'==============================================
dim rs,sql,rscount
set rs=server.CreateObject("ADODB.recordset")
sql="select * from menu order by id asc"
rs.open sql,conn,1,1
rscount=rs.recordcount
'==============================================
'?????将数据存入数组
'==============================================
dim menu(35,3)?'需要按记录条数改动
dim ItemString
for i=0 to rscount-1
?if rs.eof or rs.bof then exit for
?if trim(rs("MenuUrl"))<>"" then
?ItemString=""&rs("MenuName")&""
?else
?ItemString=rs("MenuName")
?end if
?menu(i,0)=rs("ID")
?menu(i,1)=ItemString
?menu(i,2)=rs("ParentID")
?menu(i,3)=rs("Step")
?rs.movenext
next

'==============================================
'?????实现Menu
'==============================================
dim css?'样式
sub GetMenu(parentid)
?for j=0 to ubound(menu,1)
??if parentid=menu(j,2) then
??css="step"&menu(j,3)
??response.Write(""&menu(j,1)&"
")
??if menu(j,0)<>"" then

???GetMenu menu(j,0)
??end if
??end if
?next
?
end sub
%>

copyright by Lonz

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值