在mousedown事件中,是否可以取消产生的click事件?或传递信息给它?
由于神秘的原因,我需要能够通过 mousedown 事件取消单击事件。
简要地;我正在 mousedown 事件中创建上下文菜单,但是,当用户单击页面时,上下文菜单应该消失。
在这种情况下,我无法在单击上使用 mousedown 事件,因为我希望用户能够单击菜单内的链接(完整的单击永远不会移动到基于 的菜单元素)。
如果有任何帮助,可以应用 jQuery。
我希望能够防止单击事件在初始鼠标按下时发生,或者能够将信息传递给单击事件(通过originalEvent 或其他方式)。
TIA
for arcane reasons I need to be able to cancel the click event via the mousedown event.
Briefly; I am creating a context menu in the mousedown event, however, when the user clicks on the page the context menu should disappear.
I am not able to use the mousedown event over the click in that scenario as I want the user to be able to click links inside the menu ( a full click would never travel to the <a>
based menu elements ).
If it is any help, jQuery can be applied.
I would like to either be able to prevent the click event from happening from within the initial mousedown, or be able to pass information to the click event (via originalEvent or otherwise).
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嘿,我认为这就是你想要用你的代码做的事情。如果没有,我很抱歉,我可能误解了这个问题。我使用 jQuery 来完成它: http://jsfiddle.net/jackrugile/KArRD/
Hey, I think this is what you are trying to do with your code. If not, I apologize, I may have misunderstood the question. I used jQuery to get it done: http://jsfiddle.net/jackrugile/KArRD/
似乎不可能,当在
mousedown
和/或mouseup
中被阻止时,FF 和 Opera 都没有取消即将到来的click
(旁注:点击被调度如果满足某些条件,则在鼠标松开后)。测试用例: http://jsfiddle.net/ksaeU/Seems to be impossible, neither FF nor Opera didnt cancel upcoming
click
when prevented inmousedown
and/ormouseup
(as side note: click is dispatched after mouseup if certain conditions met). testcase: http://jsfiddle.net/ksaeU/我刚刚遇到了完全相同的问题。我通过在
mousedown
上关闭它并执行菜单上的mousedown
事件来修复我的上下文菜单,以便我仍然可以接收菜单上的点击,如下所示: code>hide() 函数我再次取消绑定
mousedown.ct
,以防它因单击某个项目而关闭。I have just had the exact same problem. I fixed my context menu by closing it on
mousedown
and eating themousedown
event on the menu so that I can still receive clicks on the menu, like so:And in the
hide()
function I unbind themousedown.ct
again, in case it was closed due to a click on an item.