jQUery context menu on left click

时光总嘲笑我的痴心妄想 提交于 2019-12-06 04:58:50

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 ;)

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) {

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) {

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) {

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) {
    ....}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!