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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 21:56:29  来源:igfitidea点击:

Does using event.preventDefault() in "mousedown" prevent "click" or "mouseup" event in jquery?

javascriptjqueryeventspreventdefault

提问by Madhu

I am new to jqueryand i have a doubt whether using events.preventDefault()in the mousedownor mouseupevents does prevent the clickor dblclickevent?

我是新手jquery,我怀疑events.preventDefault()mousedownormouseup事件中使用是否会阻止clickordblclick事件?

Please provide me a clarification or a sample.

请向我提供说明或样本。

Thanks in advance. Madhu

提前致谢。马杜

回答by Felix

Neither of mouseupor mousedownprevent the default click event.

既不mouseupmousedown阻止默认点击事件。

Fiddle Demo

小提琴演示

You need to use click():

你需要使用click()

$('.test').on('click', function(e) {
    e.preventDefault();
});

Fiddle Demo

小提琴演示

回答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。在这种情况下,它不会发生。