本文主要介绍了详解bootstrap用dropdown-menu实现上下文菜单的相关资料,希望通过本文能帮助到大家,需要的朋友可以参考下,希望能帮助到大家。
详解bootstrap用dropdown-menu实现上下文菜单
写在前面:
所谓上下文菜单,它与一般菜单的区别在于:
通过右键触发显示在鼠标右键点击处
鼠标在别处点击后,该菜单消失
实现方法:
在html中定义一个普通的没有触发条件的dropdown-menu,然后写这个menu的父容器的监听即可实现。
代码:
<p id="settingInGraph">
<ul class="dropdown-menu" role="menu"
aria-labelledby="dropdownMenu" id="contextMenu">
<li><a tabindex="-1" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >任务指派</a></li>
<li><a tabindex="-1" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >任务监听</a></li>
<li><a tabindex="-1" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >任务表单</a></li>
<li class="pider"></li>
<li><a tabindex="-1" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >...</a></li>
</ul>
</p>$("#settingInGraph").mousedown(function(e) {
if (3 == e.which) {
document.oncontextmenu = function() {return false;}
$("#contextMenu").hide();
$("#contextMenu").attr("style","display: block; position: fixed; top:"
+ e.pageY
+ "px; left:"
+ e.pageX
+ "px; width: 180px;");
$("#contextMenu").show();
}
});
$("#settingInGraph").click(function(e) {
$("#contextMenu").hide(); });相关推荐:
实例讲解bootstrap paginator分页插件的两种使用方式
以上就是实例详解bootstrap用dropdown-menu实现上下文菜单的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号