左键单击 jQUEry 上下文菜单

发布于 2024-10-12 22:28:41 字数 535 浏览 2 评论 0原文

我正在使用 Chris Domigan 的 jQuery 上下文菜单插件 来应用上下文菜单。它是这样工作的:

$('#contacts tbody tr').contextMenu('myMenu1', {
    bindings: {
        'copy': function(t) {
             alert('Trigger was '+t.id+'\nAction was Copy');
         },

        'delete': function(t) {
             alert('Trigger was '+t.id+'\nAction was Delete');
        }
    },             
});

现在我希望此上下文菜单出现在左键单击而不是右键单击时。我在文档中找不到选项。有什么想法如何做到这一点吗?我需要修改源吗?

I am using jQuery context menu plugin by Chris Domigan to appy a context menu. This is how it works:

$('#contacts tbody tr').contextMenu('myMenu1', {
    bindings: {
        'copy': function(t) {
             alert('Trigger was '+t.id+'\nAction was Copy');
         },

        'delete': function(t) {
             alert('Trigger was '+t.id+'\nAction was Delete');
        }
    },             
});

Now I want this context menu to appear on left click instead of right click. I can not find an option in the doc. Any ideas how to do that? Do I have to modify the source?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

我三岁 2024-10-19 22:28:41

我知道它很旧,但无论如何我都会回答它;)

如果您想在左键单击时调用 ContextMenu,只需将行:更改

$(this).bind('contextmenu', function(e) {

为:

$(this).bind('click', function(e) {

但如果您想捕获更多事件以显示 ContextMenu,您可以添加事件名称空格键之后,根据 jQuery .bind() 参考。

例如,如果您想在左键单击和右键单击上显示菜单,只需将该行更改为:

$(this).bind('contextmenu click', function(e) {

I know it's old, but i'll answer it anyways ;)

If you want to call ContextMenu on left-click, just change the line:

$(this).bind('contextmenu', function(e) {

into this:

$(this).bind('click', function(e) {

But if You want to capture more events to display ContextMenu, You can add event names after spacebar, according to jQuery .bind() reference.

For instance, if You want to display the menu on left and right click just change the line into this:

$(this).bind('contextmenu click', function(e) {
北音执念 2024-10-19 22:28:41

看起来您需要更改代码。您需要将此行更改

 $(this).bind('contextmenu', function(e) {

为:

 $(this).bind('click', function(e) {

It looks like you would need to change the code. You need to change this line:

 $(this).bind('contextmenu', function(e) {

into this

 $(this).bind('click', function(e) {
<逆流佳人身旁 2024-10-19 22:28:41

正如来源上的标题

ContextMenu - 用于右键单击上下文菜单的 jQuery 插件

另外,在文档中没有有关如何更改单击类型的信息。我认为你唯一能做的就是扩展该代码以使用基本的“click()”;)

As the title on the source

ContextMenu - jQuery plugin for right-click context menus

Also in the doc there's no info about how to change the kind of click. I think the only thing you could do is to extend that code to work with the basic "click()" too ;)

花开浅夏 2024-10-19 22:28:41

马修·马内拉(Matthew Manela),感谢您的片段(此时花了几个小时)

另外,在我的项目中,我想支持右键单击和左键单击。
(也许有人会需要)
为此,您将代码更改为:

$(this).bind('click contextmenu', function(e) {

Matthew Manela, thanks for your snippet (spent hours at this point)

Also, in my project I want to support both right and left click.
(Maybe someone would need that)
To do this you change your code to:

$(this).bind('click contextmenu', function(e) {
葵雨 2024-10-19 22:28:41

我知道我现在说这个已经太晚了。

新的 contextjs 插件使用“on”而不是绑定,因为“on”可以像这样定义选择器:

$(document)on('contextmenu','selector',function(e){

我用它来定义我的“左”或“右”:

if(type === 'right'){
    $(document).on('contextmenu', selector, function (e) {
    ....}
else{
    $(document).on('click', selector, function (e) {
    ....}

i know that this is far too late for me to say this.

new contextjs plugin using 'on' instead of bind, because 'on' can define selector like this:

$(document)on('contextmenu','selector',function(e){

i use this to define my 'left' or 'right' :

if(type === 'right'){
    $(document).on('contextmenu', selector, function (e) {
    ....}
else{
    $(document).on('click', selector, function (e) {
    ....}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文