Javascript 同一个元素上的 Angular 2 (click) 和 (dblclick) 不起作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36113861/
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
Angular 2 (click) and (dblclick) on the same element not working good?
提问by Teddy
When I do this:
当我这样做时:
<div (click)="func1()" (dblclick)="func2()">Some text</h1>
I actually get "func1()" to fire even on dblclick twice.
实际上,即使在两次 dblclick 上,我也会触发“func1()”。
How can I make it work on the same element and work good?
我怎样才能让它在相同的元素上工作并且很好地工作?
采纳答案by Günter Z?chbauer
Doesn't seem to be an Angular issue. See https://css-tricks.com/snippets/javascript/bind-different-events-to-click-and-double-click/
似乎不是 Angular 的问题。见https://css-tricks.com/snippets/javascript/bind-different-events-to-click-and-double-click/
The workaround is to not process the click event when a dblclick happens shortly afterwards.
解决方法是在不久之后发生 dblclick 时不处理 click 事件。