详解bootstrap用dropdown-menu实现上下文菜单
写在前面:
所谓上下文菜单,它与一般菜单的区别在于:
通过右键触发显示在鼠标右键点击处
鼠标在别处点击后,该菜单消失
实现方法:
在html中定义一个普通的没有触发条件的dropdown-menu,然后写这个menu的父容器的监听即可实现。
代码:
<div id="settingInGraph">
<ul class="dropdown-menu" role="menu"
aria-labelledby="dropdownMenu" id="contextMenu">
<li><a tabindex="-1" rel="nofollow noopener noreferrer" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >任务指派</a></li>
<li><a tabindex="-1" rel="nofollow noopener noreferrer" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >任务监听</a></li>
<li><a tabindex="-1" rel="nofollow noopener noreferrer" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >任务表单</a></li>
<li class="divider"></li>
<li><a tabindex="-1" rel="nofollow noopener noreferrer" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >...</a></li>
</ul>
</div>
$("#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用dropdown-menu实现上下文菜单。偶尔我只想一个人静静的就好,不受任何打扰。不是冷漠,只想放空自己,感受生命完美。从事一项事情,先就要去决定志向,志向决定之后就是要全力以赴的毫不犹豫地去实行。更多关于详解bootstrap用dropdown-menu实现上下文菜单请关注haodaima.com其它相关文章!




