javascript实现操作cookie实现的可记忆菜单 时间:2020-05-12 人气:0 可记忆菜单 <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; j0) { 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 菜单选项一 子菜单一 子菜单二 子菜单三 子菜单四 菜单选项二 子菜单一 子菜单二 子菜单三 子菜单四 菜单选项三 子菜单一 子菜单二 子菜单三 子菜单四 菜单选项四 子菜单一 子菜单二 子菜单三 子菜单四 [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 加载全部内容