Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQuery隐藏正文上的上下文菜单单击_Javascript_Jquery - Fatal编程技术网

Javascript JQuery隐藏正文上的上下文菜单单击

Javascript JQuery隐藏正文上的上下文菜单单击,javascript,jquery,Javascript,Jquery,我想在我的页面上添加两个右键点击劫持菜单,我有一个在上面工作 与单击.square内部时的操作类似,我希望此菜单隐藏在body click上,而不考虑右键或左键单击 如何在单击正文时隐藏此菜单?请尝试下面的代码 jQuery(document).click(function(event) { if (jQuery(event.target).closest('.square').length === 0) { //hide your menu here jQuery('.

我想在我的页面上添加两个右键点击劫持菜单,我有一个在上面工作

与单击
.square
内部时的操作类似,我希望此菜单隐藏在body click上,而不考虑右键或左键单击

如何在单击正文时隐藏此菜单?请尝试下面的代码

 jQuery(document).click(function(event) {
   if (jQuery(event.target).closest('.square').length === 0) {
    //hide your menu here
    jQuery('.custom-menu').hide();
   }
  });
jQuery(document).on("contextmenu",function(e){
  if (jQuery(event.target).closest('.square').length === 0) {
    $('.custom-menu').hide();
  }
});
右键单击“添加下面的代码”

 jQuery(document).click(function(event) {
   if (jQuery(event.target).closest('.square').length === 0) {
    //hide your menu here
    jQuery('.custom-menu').hide();
   }
  });
jQuery(document).on("contextmenu",function(e){
  if (jQuery(event.target).closest('.square').length === 0) {
    $('.custom-menu').hide();
  }
});

这是附加代码,不是为了替换任何当前代码吗?--适用于左键单击,但不适用于右键单击。这是仅添加到现有代码中的附加代码。对于contextmenu事件兼容性检查,这里似乎可以将整个JSFIDLE最小化很多。。。我不能说这是可行的,但是,谢谢:)为了节省一点时间,我的代码是否都需要这样的工作版本是的,现在可以了。