樹狀菜單 點擊一個關閉另一個 默認第一個欄目的子欄目展開

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
<style type="text/css">
<!--
body {
 margin-left: 0px;
 margin-top: 0px;
 margin-right: 0px;
 margin-bottom: 0px;
}
-->
</style>
<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%;}
a:link,a:visited {color:#385065;text-decoration:none}
a:hover {text-decoration:underline}
#menu {width:150px;margin:0px 15px;padding:0px;text-align:left;list-style:none}
#menu .item {margin:5px 0px;padding:0px;list-style:none}
a.title:link, a.title:visited, a.title:hover {display:block;background:url(../images/m20069110491.gif) no-repeat;color:#385065;font-weight:bold;padding:2px 0 0 22px;width:128px;line-height:23px;cursor:pointer;text-decoration:none}
#menu .item ul {border:1px solid #9FACB7;margin:0;width:118px;padding:3px 0px 3px 30px;background:#fff;list-style:none;display:none}
#menu .item ul li {display:block;}
</style>
</head>

<body>

<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>


<table width="184" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><img src="../images/admin_left_1.gif" width="184" height="11" /></td>
  </tr>
  <tr>
    <td height="400" valign="top" background="../images/admin_left_2.gif"><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="addproduct.aspx" target="mainFrame">添加商品</a></li>
  <li><a href="addnews.aspx" target="mainFrame">添加新聞</a></li>
  <li><a href="addtype.aspx" target="mainFrame">添加商品類別</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="productlist.aspx" target="mainFrame">商品列表</a></li>
  <li><a href="newslist.aspx" target="mainFrame">新聞列表</a></li>
  <li><a href="#" target="mainFrame">訂單列表</a></li>
  <li><a href="typelist.aspx" target="mainFrame">商品分類列表</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="#" target="mainFrame">會員管理</a></li>
  <li><a href="#" target="mainFrame">管理員設置</a></li>
  <li><a href="#" target="mainFrame">店中店申請</a></li>
  <li><a href="#" target="mainFrame">退出系統</a></li>
  </ul>
</li>
</ul></td>
  </tr>
  <tr>
    <td><img src="../images/admin_left_3.gif" width="184" height="11" /></td>
  </tr>
</table>
</body>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章