js带记忆功能伸缩菜单的IE6兼容?
大家好:下面是一个很好用的带记忆功能伸缩菜单,适用于未使用框架结构网站后台页面,但是在IE6下无法记忆菜单的展开状态,哪位高手能修改一下,让它也兼容IE6?<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>带记忆功能的伸缩菜单</title>
</head>
<body>
<ul>
<li>
<a href="javascript:;" onclick="show('ol1')">国内新闻</a>
<ol class="itemmenu" id="ol1" style="display:none;">
<li><a href="#">A</a></li>
<li><a href="#">B</a></li>
<li><a href="#">C</a></li>
</ol>
</li>
<li>
<a href="javascript:;" onclick="show('ol2')">国际新闻</a>
<ol class="itemmenu" id="ol2" style="display:none;">
<li><a href="#">D</a></li>
<li><a href="#">E</a></li>
<li><a href="#">F</a></li>
</ol>
</li>
<li>
<a href="javascript:;" onclick="show('ol3')">宇宙新闻</a>
<ol class="itemmenu" id="ol3" style="display:none;">
<li><a href="#">G</a></li>
<li><a href="#">H</a></li>
<li><a href="#">I</a></li>
</ol>
</li>
</ul>
</body>
</html>
<script language="javascript" type="text/javascript">
function $(obj){
return document.getElementById(obj);
}
//初始化左边菜单
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;
}
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 show(obj){
if($(obj).style.display == "none"){
$(obj).style.display = "block";
}else{
$(obj).style.display = "none";
}
setAllItemCookie();
}
function setAllItemCookie(){
//遍历菜单入库操作
var strCookieMenu = "";
var items = document.getElementsByClassName("itemmenu");
for(var i = 0;i<items.length;i++){
if(items[i].style.display=="block"){
strCookieMenu += items[i].id + ",";
}
}
setCookie("product-menu",strCookieMenu,1);
}
window.onload = function(){
//初始化菜单
try
{
var currMenu = getCookie("product-menu");
var arrMenu = currMenu.split(",");
for(var i = 0;i < arrMenu.length;i++){
$(arrMenu[i]).style.display = "block";
}
}
catch(e)
{
}
}
</script>