以展开刷新不改变的二级树形菜单,大类点击不展开小类,小类有旁边的图标展开。
<!--#include file="conn.asp"-->
<SCRIPT language=JavaScript>
var __cc_uid="shenglu";
</SCRIPT>
<SCRIPT type=text/javascript>
var persistmenu="yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only
if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">/n')
document.write('.submenu{display: none;}/n')
document.write('</style>/n')
}
function SwitchMenu(obj){
if(document.getElementById){
var el = document.getElementById(obj);
var ar = document.getElementById("masterdiv").getElementsByTagName("tr"); //DynamicDrive.com change
if(el.style.display != "block"){ //DynamicDrive.com change
for (var i=0; i<ar.length; i++){
if (ar[i].className=="submenu") //DynamicDrive.com change
ar[i].style.display = "none";
}
el.style.display = "block";
}else{
el.style.display = "none";
}
}
}
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function onloadfunction(){
if (persistmenu=="yes"){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=get_cookie(cookiename)
if (cookievalue!="")
document.getElementById(cookievalue).style.display="block"
}
}
function savemenustate(){
var inc=1, blockid=""
while (document.getElementById("sub"+inc)){
if (document.getElementById("sub"+inc).style.display=="block"){
blockid="sub"+inc
break
}
inc++
}
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
document.cookie=cookiename+"="+cookievalue
}
if (window.addEventListener)
window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
window.onload=onloadfunction
if (persistmenu=="yes" && document.getElementById)
window.onunload=savemenustate
</SCRIPT>
<STYLE type=text/css>.menutitle {
PADDING-RIGHT: 1px; PADDING-LEFT: 1px; MARGIN-BOTTOM: 1px; PADDING-BOTTOM: 1px; MARGIN-LEFT: auto; WIDTH: 200px; CURSOR: pointer; COLOR: #000000; MARGIN-RIGHT: auto; font-size:12px;font-weight:bold;
}
.submenu {
MARGIN-BOTTOM: 0.5em
}
</STYLE>
<table width="200" border="0" cellspacing="0" cellpadding="0" align="left">
<Tr><td class="catalog" align="center" bgcolor="#666666" height="25">Product Catalog</td></Tr>
<tr>
<td>
<!--菜单开始--><TABLE id=masterdiv cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
<TBODY>
<%
set rsBigClass1=server.CreateObject("adodb.recordset")
rsBigClass1.open "Select * From type1",conn,1,1
j=0
do while not rsBigClass1.eof
bigclassname=rsbigclass1("bigclassname")
sanjib=bigclassname
if inStr(sanjib," ")>0 then '判断是否含有“ ”字符
sanjib=replace(sanjib," ","-") '替换“ ”字符为“-”
end if
j=j+1
%>
<TR class=menutitle>
<TD height="20"> <a href="product_<%=sanjib%>__page_1.htm" class="leftmenu"><%=rsBigClass1("BigClassName")%></a>
</TD><Td valign="middle" onClick="SwitchMenu('sub<%=j%>')"><a href="#" onClick="javascript:showtable<%="a"&i%>();"><%set rscheck=server.CreateObject("adodb.recordset")
rscheck.open "Select * From type2 Where bigclassid=" & rsBigClass1("bigclassid"),conn,1,1
if not(rscheck.bof and rscheck.eof) then%><img src=image/nvdown.jpg border="0"><%end if%></a></td></TR>
<TR class=submenu id=sub<%=j%>>
<TD colspan="2">
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<%
set rsSmallClass1=server.CreateObject("adodb.recordset")
rsSmallClass1.open "Select * From type2 Where bigclassid=" & rsBigClass1("bigclassid"),conn,1,1
if not(rsSmallClass1.bof and rsSmallClass1.eof) then
do while not rsSmallClass1.eof
smallclassname=rssmallclass1("smallclassname")
sanjis=smallclassname
if inStr(sanjis," ")>0 then '判断是否含有“ ”字符
sanjis=replace(sanjis," ","-") '替换“ ”字符为“-”
end if
%>
<tr><Td><a href="product_<%=sanjib%>_<%=sanjis%>_page_1.htm" class="leftmenu"> <%=rsSmallClass1("SmallClassName")%></a></Td></tr>
<%
rsSmallClass1.movenext
loop
end if
rsSmallClass1.close
set rsSmallClass1=nothing %>
</TBODY></TABLE>
</TD></TR>
<%
rsBigClass1.movenext
loop
rsbigclass1.close
set rsbigclass1=nothing%>
</TBODY></TABLE></td>
</tr>
<Tr><Td height="25"></Td></Tr>
</table>
http://www.corange.cn/archives/2008/04/914.html