Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在禁用上下文菜单时,右键单击将回调分配给jQuery_Javascript_Jquery_Contextmenu_Right Click - Fatal编程技术网

Javascript 在禁用上下文菜单时,右键单击将回调分配给jQuery

Javascript 在禁用上下文菜单时,右键单击将回调分配给jQuery,javascript,jquery,contextmenu,right-click,Javascript,Jquery,Contextmenu,Right Click,在禁用关联菜单时,是否可以为右键单击分配回调函数 你快到了。右键单击时会触发上下文菜单事件。因此,在该处理程序中,您应该执行您想要的操作,然后e.preventDefault() 这将是一种更方便的方法: $('div').on('contextmenu', function (e) { if(!$(this).children('label').is(e.target)){ e.preventDefault(); return false; }

在禁用关联菜单时,是否可以为右键单击分配回调函数


你快到了。右键单击时会触发
上下文菜单
事件。因此,在该处理程序中,您应该执行您想要的操作,然后
e.preventDefault()


这将是一种更方便的方法:

$('div').on('contextmenu', function (e) {
    if(!$(this).children('label').is(e.target)){
        e.preventDefault();
        return false;
    }
});

$('label').on('contextmenu', function (e) {
    alert(1);
    e.preventDefault();
    return false;
});
$('div').on('contextmenu', function (e) {
    var btn = e.button;
    if (btn == 2) {
        alert(1);
    } else {
        return false;
    }

    e.preventDefault();
    return false;
});
$('div').on('contextmenu', function (e) {
    if(!$(this).children('label').is(e.target)){
        e.preventDefault();
        return false;
    }
});

$('label').on('contextmenu', function (e) {
    alert(1);
    e.preventDefault();
    return false;
});