您的位置:首页 > Web前端 > JavaScript

二级JS菜单

2008-04-10 09:02 288 查看
近日一个项目用到一个二级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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: