示例代码:简单上下文菜单
右键点击链接后弹出这个弹出窗口...但是点击网站上的任何一个单元格后都想得到相同的结果。
$(function(){
$.contextMenu({
selector: '.context-menu-one',
callback: function(key, options) {
var m = "clicked: " + key;
window.console && console.log(m) || alert(m);
},
items: {
"edit": {name: "Edit", icon: "edit"},
"cut": {name: "Cut", icon: "cut"},
"copy": {name: "Copy", icon: "copy"},
"paste": {name: "Paste", icon: "paste"},
"delete": {name: "Delete", icon: "delete"},
"sep1": "---------",
"quit": {name: "Quit", icon: "quit"}
}
});
$('.context-menu-one').on('click', function(e){
console.log('clicked', this);
})
});
<div class="context-menu-one box menu-1">
<strong>right click me</strong>
</div>
答案 0 :(得分:1)
要让您的脚本在整个页面上触发,请更改您的选择器:
selector: 'body',