单击鼠标中键时,Firefox中的PreventDefault无法正常工作 [英] PreventDefault is not working in firefox on mouse middle button click
本文介绍了单击鼠标中键时,Firefox中的PreventDefault无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hii,
单击鼠标滚轮时我需要阻止滚动。
preventDefault()方法在Chrome中有效但是它不适用于Firefox.
任何帮助?
这是我的代码:
$(document).bind(' mousedown',函数(e){
if ((e.which == 2 )){
e.preventDefault();
}
});
解决方案
(document).bind(' mousedown',function(e) {
if ((e.which == 2 )){
e.preventDefault();
}
});
mousedown
和单击
事件一起发生,并且不共享相同的事件对象。
在mousedown中调用
事件无法阻止点击事件的默认点击行为。e.preventDefault();
为什么它在Chrome中适用于你很可能是另一个原因甚至是假的积极的。
要证明,假设你有以下HTML:
< a href = http://jsfiddle.net/ id = whichkey > 链接到Google < / a >
< div id = log > < / div >
以下脚本不会阻止默认行为,单击链接将始终有效:
< pre lang =javascript>
( #whichkey)。on( mousedown, function (event){
Hii,
I need to prevent scrolling when mouse wheel is clicked.
The preventDefault() methos is working in Chrome but its not working in firefox.
Any help?
here is my code:
$(document).bind('mousedown', function (e) {
if ((e.which == 2)) {
e.preventDefault();
}
});
解决方案
(document).bind('mousedown', function (e) { if ((e.which == 2)) { e.preventDefault(); } });
Themousedown
andclick
events occur together and are not sharing the same event object.
Callinge.preventDefault();
in themousedown
event is not able to prevent the default click behaviour on the click event.
Why it works for you in Chrome is most likely a different reason or a even false positive.
To Demonstrate, assuming you have the following HTML:
<a href="http://jsfiddle.net/" id="whichkey">link to google</a> <div id="log"></div>
The following Script will not prevent the default behaviour and clicking the link will always work:
("#whichkey").on("mousedown", function (event) {
这篇关于单击鼠标中键时,Firefox中的PreventDefault无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文