JS实现点击某个图标展开关联菜单

本文介绍了一个使用JSP、JavaScript和CSS实现的菜单弹窗功能。通过鼠标点击事件触发弹窗显示隐藏,并实现了菜单项的hover效果。适用于网页中需要快速调用配置选项的场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

JSP代码:

<body>
	<div align="center">
		<center>
			<table id="itemopen" class="box" style="display: none">
				<tr>
					<td><a class="cc">Remove</a></td>
				</tr>
				<tr>
					<td><a class="cc">Inactive</a></td>
				</tr>
				<tr>
					<td><a class="cc">Copy as New</a></td>
				</tr>
				<tr>
					<td><a class="cc">Properties</a></td>
				</tr>
			</table>
		</center>
	</div>

<span style="white-space:pre">	</span><img onCLick="popUp()" src="../base/images/index/config.png" style="float:right;padding-right:10px;cursor:hand;"/>
</body>


JS代码:

</pre><pre code_snippet_id="408372" snippet_file_name="blog_20140627_5_5161102" name="code" class="plain"><pre name="code" class="javascript">function popUp() {
		newX = window.event.x + document.body.scrollLeft;//获取x轴位置
		newY = window.event.y + document.body.scrollTop;//获取y轴位置
		menu = document.all.itemopen;
		  if ( menu.style.display == "")
		  	{
		    menu.style.display = "none" ;
		    }
		  else 
		  	{
		     menu.style.display = "";
		     }
		    menu.style.left = newX - 80;
		    menu.style.top = newY + 5; //向下挪5个像素,避免盖住半个操作按钮
		}

CSS:


<pre name="code" class="javascript">.box {
	position: absolute;
	background: white;
	border: 1px solid #CCC;
	z-index:100;
}

itemopen.cc:hover {
	cursor: hand;
	color: #E4E8EE;
	text-decoration: none;
}
</style>
</pre><pre>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值