Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.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,如何禁用鼠标滚轮点击链接_Javascript_Jquery - Fatal编程技术网

Javascript,如何禁用鼠标滚轮点击链接

Javascript,如何禁用鼠标滚轮点击链接,javascript,jquery,Javascript,Jquery,我试图禁用鼠标滚轮点击链接,但我不知道为什么它不起作用。 这是我的密码: html: <a class="disable_mousewheel_event" href="https://code.jquery.com/">Click</a> $(文档)。在(“单击”)上,函数(e){ if($(e.target).is(“a[href]”&&e.button==1){ e、 预防默认值(); } }); 在鼠标上不会打开选项卡。它发生在mousedown上“mous

我试图禁用鼠标滚轮点击链接,但我不知道为什么它不起作用。 这是我的密码:

html:

<a class="disable_mousewheel_event" href="https://code.jquery.com/">Click</a>
$(文档)。在(“单击”)上,函数(e){
if($(e.target).is(“a[href]”&&e.button==1){
e、 预防默认值();
}
});


鼠标上不会打开选项卡。它发生在
mousedown
上“mouseup”与按下按钮有关。签出控制盘事件。我已经尝试了“return false”和“mousedown”。不起作用。禁用鼠标中键几乎总是错误的方法。您是否也要禁用
ctrl+单击
?如果有人真的想在新选项卡中打开链接,您不能阻止他们。@zzzzBox他实际上也是这样做的,他的示例不起作用,但是您将其标记为重复。男:是的
$(function() {
    $(".disable_mousewheel_event").on("mouseup", function(event) {
        if (event.which == 2) {
            event.preventDefault();
        }
    });
})