代碼如下
<% class menusPublic Title, ID, Image, TitleColor, Target, Background, HeadImage, Height, Width, Bgcolor, StylePrivate menuItem, menuStrPrivate Sub Class_Initialize Title = "" ID = "" menuItem = "" Image="" TitleColor = "#000000" Target = "_blank" Background = "" HeadImage = "" Height = "20" Width = "100%" Bgcolor = "" Style = "" scriptEnd SubPrivate Sub Class_Terminate Title = "" ID = "" menuItem = ""End SubPublic Function AddItem(Byval nItem, Byval nURL) menuItem = menuItem & "<tr><td style='font-size:12px;' align='left'> {$Image}<a href='" & nURL & "' target='"&Target&"' class='"& Style &"'>" & nItem & "</a></td></tr>"End FunctionPublic Sub Show() menuStr = "<table border=0 width='"& Width &"' style='border:1px solid #999999;' bgcolor='"& Bgcolor &"'><tr><td height='"& Height &"' Onclick=menus('" & ID & "') bgcolor='"& Bgcolor &"' valign='bottom' style='" & _ "font-size:12px;color:"&TitleColor&";cursor: hand;' background='"&Background&"' align='left'> {$HeadImage}" & Title & "</td></tr></table><p id=" & chr(34) & ID & chr(34) & " style=" &chr(34) & _ "display:none;"& chr(34) & "><table width=100% border=0 style='border-left:1px solid #999999;border-right:1px solid #999999;border-bottom:1px solid #999999;'>" & menuItem & "</table></p>" if Image<>"" then menuStr = replace(menuStr, "{$Image}", Image) else menuStr = replace(menuStr, "{$Image}", "") end if if HeadImage<>"" then menuStr = replace(menuStr, "{$HeadImage}", HeadImage) else menuStr = replace(menuStr, "{$HeadImage}", "") end if Response.Write menuStrEnd SubPrivate Function script() Dim JScript JScript = "<script language="&chr(34)&"JavaScript"&chr(34)&"type="&chr(34)&"text/JavaScript"&chr(34)& _">"&vbcrlf&"<!--"&vbcrlf&"function menus(str){"&vbcrlf&"var obj;if (document.getElementById(str)){"&vbcrlf& _"obj=document.getElementById(str);"& _"if (obj.style.display =="&chr(34)&"none"&chr(34)&"){obj.style.display ="&chr(34)&chr(34)& _";}else{obj.style.display ="&chr(34)&"none"&chr(34)&";}}}//--></script>" response.Write JScriptEnd FunctionPublic Sub AddNew() Title = "" ID = "" menuItem = "" menuStr = ""End SubPublic Sub OpenItem(Byval ItemID)End Subend class%>
使用方法:
<%Dim NewMenusSet NewMenus = new menusNewMenus.Target = "" '開啟檔案NewMenus.Bgcolor = "#336699" '主標籤背景色NewMenus.TitleColor = "#FFFFFF" '主標籤字型顏色NewMenus.Height = "10px" '高度NewMenus.Style ="a1" '子標籤樣式NewMenus.Width = "100%" '菜單寬度NewMenus.AddNewNewMenus.Title = "門戶網站"NewMenus.ID = "menu1"NewMenus.AddItem "網易", "http://www.163.com"NewMenus.AddItem "搜狐", "http://www.sohu.com"NewMenus.ShowNewMenus.AddNewNewMenus.Title = "個人網站"NewMenus.ID = "menu2"NewMenus.AddItem "IEBSoft studio", "http://iebsoft.512j.com"NewMenus.AddItem "租用的空間", "http://107814.hxidc.com"NewMenus.ShowNewMenus.AddNewNewMenus.Title = "網站新聞管理"NewMenus.ID = "menu3"NewMenus.AddItem "新聞列表", "#"NewMenus.AddItem "圖片新聞", "#"NewMenus.AddItem "新聞管理", "#"NewMenus.ShowSet NewMenus = Nothing%>