代码简介:一款可以用到后台管理的左侧的JS折叠菜单,而且加入主Cookies技术,使得操作项可以适时保存,也就是当您刷新页面的时候,你上次打开菜单的当前项不会改变,直至Cookies失效为止。而且它的外观也挺漂亮的,相信开发网站的朋友会用得上。
代码内容:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="UTF-8" lang="UTF-8"> <head> <title>用于用户中心或后台左侧的JS折叠菜单_网页代码站(www.webdm.cn)</title> <style type="text/css"> body {margin:0;text-align:center;color:#000;font:normal 12px Arial,Verdana,Tahoma;text-align:center;background:#C8D0D5;line- height:150%;}/*www.webdm.cn*/ a:link,a:visited {color:#385065;text-decoration:none} a:hover {text-decoration:underline} #menu {150px;margin:0px 15px;padding:0px;text-align:left;list-style:none} #menu .item {margin:5px 0px;padding:0px;list-style:none}/*www.webdm.cn*/ a.title:link, a.title:visited, a.title:hover {display:block;background:url(http://www.webdm.cn/images/20090914/m201.gif) no- repeat;color:#385065;font-weight:bold;padding:2px 0 0 22px;128px;line-height:23px;cursor:pointer;text-decoration:none} #menu .item ul {border:1px solid #9FACB7;margin:0;118px;padding:3px 0px 3px 30px;background:#fff;list-style:none;display:none} #menu .item ul li {display:block;} </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> <ul id="menu"> <li class="item"><a href="javascript:void(0)" class="title" name="1">网站设置</a> <ul id="opt_1" class="optiton"> <li><a href="http://www.webdm.cn">基本设置</a></li> <li><a href="#">高级设置</a></li> </ul> </li> <li class="item"><a href="javascript:void(0)" class="title" name="2">生成管理</a> <ul id="opt_2" class="optiton"> <li><a href="http://www.webdm.cn">生成首页</a></li> <li><a href="#">生成列表</a></li> </ul> </li> <li class="item"><a href="javascript:void(0)" class="title" name="3">系统管理</a> <ul id="opt_3" class="optiton"> <li><a href="http://www.webdm.cn">会员管理</a></li> <li><a href="#">管理员设置</a></li> <li><a href="#">退出系统</a></li> </ul> </li> </ul> </body> </html> <br> <a href="http://www.webdm.cn">网页代码站</a> - 最专业的代码下载网站 - 致力为中国站长提供有质量的代码!
代码来自:http://www.webdm.cn/webcode/f4af47f1-5241-4fa0-aa71-1f0a2eb376e1.html