二级JS菜单

来源:互联网 发布:电视台回看软件 编辑:程序博客网 时间:2024/04/28 05:02

 近日一个项目用到一个二级JS菜单,先将代码记录在此,以便下次利用:

<head>

<script>
startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
}
node.onmouseout=function() {
this.className=this.className.replace(" over", "");
}
}
}
}
}
window.onload=startList;
</script>
<link href="css/2008_style.css" rel="stylesheet" type="text/css" />

<style>
ul {
margin: 0;
padding: 0;
list-style: none;
text-align:left;
width: 130px; /* Width of Menu Items */
border-bottom: 0px solid #ccc;
}
ul li {
position: relative;
}
li ul {
position: absolute;
left: 129px; /* Set 1px less than menu width */
top: 0;
display: none;
}
/* Styles for Menu Items */
ul li a {
display: block;
text-decoration: none;
color:#555;
background: #fff; /* IE6 Bug */
padding:3px 0;
border: 0px solid #ccc;
border-bottom: 0;
}
/* Fix IE. Hide from IE Mac /*/
* html ul li { float: left; height: 1%; }
* html ul li a { height: 1%; }
/* End */
ul li a:hover { color: #1e58a0; background: #f6f8f8; } /* Hover Styles */
li ul li a { padding: 2px 5px; } /* Sub Menu Styles */
li:hover ul, li.over ul { display: block; } /* The magic */
</style>
</head>
<body>

<ul id="nav">

 <li><a href="#">a1</a>
  <ul>
  <li><a href="#">a1</a></li>
  </ul>
 </li>
 <li><a href="#">a2</a>
  <ul>
  <li><a href="#">a1</a></li>
  <li><a href="#">a2</a></li>
  </ul>
 </li>
</ul>
</body>

原创粉丝点击