二级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>
<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>
相关文章推荐
- js实现的全国省市二级联动下拉选择菜单完整实例
- js+css二级菜单制作方法
- js实现的黑背景灰色二级导航菜单效果代码
- js 二级联动菜单
- js实现向右横向滑出的二级菜单效果
- 一个简单的js的省市二级联动菜单(转)
- js简单的二级级联菜单
- 超简单实用的竖形二级菜单(JS)
- JS 实现导航菜单中的二级下拉菜单的几种方式
- JS中用三种方式实现导航菜单中的二级下拉菜单
- 第十五篇 JS 移入移出事件 模拟一个二级菜单
- js生成二级城市联动菜单,动态生成年、月、日字段,生产一个验证码
- Ajax、js、 xml 、jsp菜单 测试二级联动查询
- JS+CSS实现简单的二级下拉导航菜单效果
- CSS控制二级菜单动态出现不只有js才能做到
- js二级联动菜单
- js二级菜单的制作(有动画)
- DIV+CSS+JS二级树型菜单,刷新无影响
- js实现二级菜单点击显示当前内容效果
- jsp+js实现的二级联动菜单