屏蔽默认右键菜单

Jquery

$(document).bind("contextmenu",function(e){
        return false;
});

js

document.oncontextmenu = function(e){
    return false;
}

之后就可以自定义右键菜单

 $("#flight_box").on("mousedown", ".table_list tr td", function (e) {
     e.stopPropagation();
     if (3 == e.which) { //右键按下
         xxx
     }
})

PS

oncontextmenu 事件在元素中用户右击鼠标时触发并打开上下文菜单。


<html>
<head>
<meta charset="utf-8">
<style>
div {
    background: yellow;
    border: 1px solid black;
    padding: 10px;
}
style>
head>
<body>

<div oncontextmenu="myFunction()" contextmenu="mymenu">
<p>在文本框内右击鼠标查看上下文菜单!p>
<menu type="context" id="mymenu">
  <menuitem label="Refresh" onclick="window.location.reload();" icon="ico_reload.png">menuitem>
  <menu label="Share on...">
    <menuitem label="Twitter" icon="ico_twitter.png" onclick="window.open('//twitter.com/intent/tweet?text=' + window.location.href);">menuitem>
    <menuitem label="Facebook" icon="ico_facebook.png" onclick="window.open('//facebook.com/sharer/sharer.php?u=' + window.location.href);">menuitem>
  menu>
  <menuitem label="向该网页发送邮件" onclick="window.location='mailto:?body='+window.location.href;">menuitem>
menu>
div>
<script>
function myFunction() {
    alert("你在 div 元素总点击鼠标了右键。");
}
script>
<p><strong>注意:strong> 只有 Firefox 中支持  contextmenu <strong>属性strong> !p>

body>
html>

你可能感兴趣的:(JavaScript)