Cookie记住菜单状态的问题
<head>
<style type="text/css">
BODY { FONT-SIZE: 12px;}
TD { FONT-SIZE: 12px; line-height: 150%}
.resizeDivClass
{
position:relative;
background-color:red;
width:2;
z-index:1;
left:expression(this.parentElement.offsetWidth-1);
cursor:e-resize;
}
a:link,a:visited {color:#385065;text-decoration:none}
a:hover {text-decoration:underline; color:#6699cc}
a:active{color:Red;text-decoration:none}
#menu {width:100%;margin:0px 0px;padding:0px;text-align:left;list-style:none; height:370px}
#menu.item:hover { COLOR:white; font-weight:bold; FONT-SIZE: 12px; TEXT-DECORATION: none; background-color:olivedrab; display:block; width:100%; line-height:12pt;}
#menu .item {margin:0px 0px;padding:0px;list-style:none}
a.title:link, a.title:visited, a.title:hover {display:block;color:Black;font-weight:bold;padding:0px 0 0 0px;width:100%;line-height:23px;cursor:pointer;text-decoration:none;}
#menu .item ul {border:1px solid #9FACB7;margin:0;width:100%;padding:0px 0px 0px 0px;background:#fff;list-style:none;display:none;height:370px}
#menu .item ul li {display:block;}
#menu .item ul li a:hover {Color:white;font-weight:bold; FONT-SIZE: 12px; TEXT-DECORATION: none; background-color:olivedrab; display:block; width:100%; line-height:12pt;}
</style>
<script language="javascript" type="text/javascript">
// --- 获取ClassName
document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var j = 0; j < elem.length; j++) {
var classes = elem[j].className;
if (myclass.test(classes)) retnode.push(elem[j]);
}
return retnode;
}
// --- 隐藏所有
function HideAll() {
var items = document.getElementsByClassName("optiton");
for (var j=0; j<items.length; j++) {
items[j].style.display = "none";
}
}
// --- 设置cookie
function setCookie(sName,sValue,expireHours) {
var cookieString = sName + "=" + escape(sValue);
//;判断是否设置过期时间
if (expireHours>0) {
var date = new Date();
date.setTime(date.getTime + expireHours * 3600 * 1000);
cookieString = cookieString + "; expire=" + date.toGMTString();
}
document.cookie = cookieString;
}
//--- 获取cookie
function getCookie(sName) {
var aCookie = document.cookie.split("; ");
for (var j=0; j < aCookie.length; j++){
var aCrumb = aCookie[j].split("=");
if (escape(sName) == aCrumb[0])
return unescape(aCrumb[1]);
}
return null;
}
window.onload = function() {
var show_item = "opt_1";
if (getCookie("show_item") != null) {
show_item= "opt_" + getCookie("show_item");
}
document.getElementById(show_item).style.display = "block";
var items = document.getElementsByClassName("title");
for (var j=0; j<items.length; j++) {
items[j].onclick = function() {
var o = document.getElementById("opt_" + this.name);
if (o.style.display != "block")
{
HideAll();
o.style.display = "block";
setCookie("show_item",this.name);
}
else {
o.style.display = "none";
}
}
}
}
</script>
</head>
<body>
<div id="divMenu" style="height:400px" runat="server">
<ul id="menu">
<li class="item" style="background-image:url(../images/menubar.gif); text-align:center; margin:1px 1px 1px 1px"><a href="#" class="title" name="1" style="width: 100%; text-align:center">管理</a>
<ul id="opt_1" class="optiton">
<li><a href="../Folder1/WForm1.aspx">收费</a></li>
<li><a href="../Folder1/WForm2.aspx">信息录入</a></li>
<li><a href="../Folder1/WForm3.aspx">记录查询</a></li>
</ul>
</li>
<li class="item" style="background-image:url(../images/menubar.gif); text-align:center; margin:1px 1px 1px 1px"><a href="#" class="title" name="2" style="width: 100%">基础数据管理</a>
<ul id="opt_2" class="optiton">
<li><a href="../Folder2/MForm1.aspx">基本管理</a></li>
<li><a href="../Folder2/MForm2.aspx">单位管理</a></li>
<li><a href="../Folder2/MForm3.aspx">标准管理</a></li>
</ul>
</li>
<li class="item" style="background-image:url(../images/menubar.gif); text-align:center; margin:1px 1px 1px 1px"><a href="#" class="title" name="3" style="width: 100%">系统帮助</a>
<ul id="opt_3" class="optiton">
<li><a href="../Folder3/Form1.aspx">帮助主题</a></li>
<li><a href="../Folder3/Form2.aspx">关于系统</a></li>
<li><a href="../Folder3/Form3.aspx">安全退出</a></li>
</ul>
</li>
</ul>
</div>
</body>