左键单击 jQUEry 上下文菜单
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我知道它很旧,但无论如何我都会回答它;)
如果您想在左键单击时调用 ContextMenu,只需将行:更改
为:
但如果您想捕获更多事件以显示 ContextMenu,您可以添加事件名称空格键之后,根据 jQuery .bind() 参考。
例如,如果您想在左键单击和右键单击上显示菜单,只需将该行更改为:
I know it's old, but i'll answer it anyways ;)
If you want to call ContextMenu on left-click, just change the line:
into this:
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:
看起来您需要更改代码。您需要将此行更改
为:
It looks like you would need to change the code. You need to change this line:
into this
正如来源上的标题
另外,在文档中没有有关如何更改单击类型的信息。我认为你唯一能做的就是扩展该代码以使用基本的“click()”;)
As the title on the source
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 ;)
马修·马内拉(Matthew Manela),感谢您的片段(此时花了几个小时)
另外,在我的项目中,我想支持右键单击和左键单击。
(也许有人会需要)
为此,您将代码更改为:
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:
我知道我现在说这个已经太晚了。
新的 contextjs 插件使用“on”而不是绑定,因为“on”可以像这样定义选择器:
我用它来定义我的“左”或“右”:
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:
i use this to define my 'left' or 'right' :