实例详解bootstrap用dropdown-menu实现上下文菜单

js教程评论912 views阅读模式

本文主要介绍了详解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栅格系统

Bootstrap 树控件使用经验分享

实例讲解bootstrap paginator分页插件的两种使用方式

以上就是实例详解bootstrap用dropdown-menu实现上下文菜单的详细内容,更多请关注php教程其它相关文章!

企鹅博客
  • 本文由 发表于 2019年9月30日 00:30:50
  • 转载请务必保留本文链接:https://www.qieseo.com/394139.html

发表评论