Javascript,如何禁用鼠标滚轮点击链接
我试图禁用鼠标滚轮点击链接,但我不知道为什么它不起作用。 这是我的密码: html: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
<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();
}
});
})