当前位置:编程学习 > JS >>

点击展开的竖向二级下拉菜单

鼠标点击后即可展开的竖向二级下拉菜单,菜单项可以自己无限制添加,有多少项就可以添多少项,本菜单代码由CSS与JavaScript共同实现,二级下拉菜单源码下载。
答案:<!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>
<title>点击展开的竖向二级下拉菜单</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<style type="text/css">
*{margin:0;padding:0;}
#nav{width:200px;margin:50px;}
#nav h3{cursor:pointer;line-height:30px;height:30px;background-color:#000000;color:#fff;}
#nav a{display:block;line-height:24px;color:#666666;}
#nav a:hover{background-color:#eee;color:#000;}
#nav div{display:none;border:1px solid #000;border-top:none;}
</style>
<script type="text/javascript">
function $(id){return document.getElementById(id)}
window.onload = function(){
	$("nav").onclick = function(e){
		var src = e?e.target:event.srcElement;
		if(src.tagName == "H3"){
			var next = src.nextElementSibling || src.nextSibling;
			next.style.display = (next.style.display =="block")?"none":"block";
		}
	}
}
</script>
</head>
<body>
<div id="nav">
	<h3>作品导航</h3>
    <div>
    <a href="#">图片切换</a>
        <a href="#">网页播放器</a>
        <a href="#">网站计数器</a>
    </div>
    <h3>查询工具</h3>
    <div>
    <a href="#">ALEXA查询</a>
        <a href="#">PageRank查询</a>
        <a href="#">收录查询</a>
    </div>
</div>
</body>
</html>

上一个:风格清新的CSS导航菜单
下一个:jQuery可伸缩的竖向下拉导航菜单

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,