简单JavaScript菜单栏的扩展与隐藏

简单的JavaScript菜单栏的扩展与隐藏

实现菜单的收缩与扩展
<body>
	<div id="leftNav" class="left-nav">
		<div id="myMenu" class="menuBox">
			<ul class="spMenuBox">
				<li class="spMenuItem active">
					<div class="spMenu" onclick="show(this.title)" title="1">
						<span>菜单1</span>
					</div>
					<ul class="subMenuBox" style="display: block;" id="d1">
						<li><span class="subMenu">菜单1.1</span></li>
						<li><span class="subMenu">菜单1.2</span></li>
						<li><span class="subMenu">菜单1.3</span></li>
					</ul>
				</li>
				<li class="spMenuItem">
					<div class="spMenu" onclick="show(this.title)" title="2">
						<span>菜单2</span>
					</div>
					<ul class="subMenuBox" style="display: none;" id="d2">
						<li><span class="subMenu">菜单2.1</span></li>
						<li><span class="subMenu">菜单2.2</span></li>
						<li><span class="subMenu">菜单2.3</span></li>
						<li><span class="subMenu">菜单2.1</span></li>
						<li><span class="subMenu">菜单2.2</span></li>
						<li><span class="subMenu">菜单2.3</span></li>
					</ul>
				</li>
				<li class="spMenuItem">
					<div class="spMenu" onclick="show(this.title)" title="3">
						<span>菜单3</span>
					</div>
					<ul class="subMenuBox" style="display: none;" id="d3">
						<li><span class="subMenu">菜单3.1</span></li>
						<li><span class="subMenu">菜单3.2</span></li>
						<li><span class="subMenu">菜单3.3</span></li>
						<li><span class="subMenu">菜单3.1</span></li>
						<li><span class="subMenu">菜单3.2</span></li>
						<li><span class="subMenu">菜单3.3</span></li>
						<li><span class="subMenu">菜单3.1</span></li>
						<li><span class="subMenu">菜单3.2</span></li>
						<li><span class="subMenu">菜单3.3</span></li>
					</ul>
				</li>
				<li class="spMenuItem">
					<div class="spMenu" onclick="show(this.title)" title="4">
						<span>菜单4</span>
					</div>
					<ul class="subMenuBox" style="display: none;" id="d4">
						<li><span class="subMenu">菜单4.1</span></li>
						<li><span class="subMenu">菜单4.2</span></li>
						<li><span class="subMenu">菜单4.3</span></li>
					</ul>
				</li>
				<li class="subMenuItem">
					
					<div class="spMenu" onclick="show(this.title)" title="5"> 
						<span>菜单5</span>
					</div>
					<ul class="subMenuBox" style="display: none;" id="d5">
						<li><span class="subMenu">菜单5.1</span></li>
						<li><span class="subMenu">菜单5.2</span></li>
						<li><span class="subMenu">菜单5.3</span></li>
						<li><span class="subMenu">菜单5.1</span></li>
						<li><span class="subMenu">菜单5.2</span></li>
						<li><span class="subMenu">菜单5.3</span></li>
					</ul>
				</li>
			</ul>
		</div>
	
	</div>
</body>
<script>
var a=true;
function show(title){
var d = document.getElementById("d"+title);
	if(a){
		d.style.display = "block";
		a = false;
		}
		else
		{
			d.style.display = "none";
			a = true;
				}
			}
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值