javascript 在“mousedown”中使用 event.preventDefault() 是否会阻止 jquery 中的“click”或“mouseup”事件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21900470/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does using event.preventDefault() in "mousedown" prevent "click" or "mouseup" event in jquery?
提问by Madhu
I am new to jquery
and i have a doubt whether using events.preventDefault()
in the mousedown
or mouseup
events does prevent the click
or dblclick
event?
我是新手jquery
,我怀疑events.preventDefault()
在mousedown
ormouseup
事件中使用是否会阻止click
ordblclick
事件?
Please provide me a clarification or a sample.
请向我提供说明或样本。
Thanks in advance. Madhu
提前致谢。马杜
回答by Felix
Neither of mouseup
or mousedown
prevent the default click event.
既不mouseup
或mousedown
阻止默认点击事件。
You need to use click()
:
你需要使用click()
:
$('.test').on('click', function(e) {
e.preventDefault();
});
回答by Quinn
It does not prevent the event itself, but the actionthat is triggeredby the event.
它不会阻止事件本身,但动作是触发该事件。
A simple example would be clicking on an anchor link. The default action of the click event is to take the browser to a new URL. In this case, it won't happen.
一个简单的例子是点击一个锚链接。单击事件的默认操作是将浏览器带到新的 URL。在这种情况下,它不会发生。