jquery:如何判断mouseup是否会跟随click事件?(jquery: how to tell if a mouseup is going to be followed by a click

编程入门 行业动态 更新时间:2024-10-22 16:33:08
jquery:如何判断mouseup是否会跟随click事件?(jquery: how to tell if a mouseup is going to be followed by a click event?)

有没有办法知道,在jQuery onmouseup处理程序中,如果事件后面会跟着同一个元素的click事件?

我有一个菜单超链接的事件处理程序,当用户点击元素或在元素上“拖放”(如在拖放中)时,它会自行解除绑定。 如果下一次click我想避免在mouseup上过早解除处理程序的绑定。

我意识到我可以自己跟踪mousedown和mouseup事件或以其他方式破解解决方案(例如,等待50毫秒以查看是否很快就会出现点击),但是我希望避免滚动我自己的实现,如果有内置的用于此目的。

Is there any way to know, in a jQuery onmouseup handler, if the event is going to be followed by a click event for the same element?

I have an event handler for a menu hyperlink which unbinds itself when the user either clicks on an element or "drops" (as in drag-n-drop) on an element. I want to avoid prematurely unbinding the handler on mouseup if a click is coming next.

I realize I can track mousedown and mouseup events myself or otherwise hack up a solution (e.g. wait 50 msecs to see if a click comes soon), but I was hoping to avoid rolling my own implementation if there's something built-in for this purpose.

最满意答案

没有内置任何东西,因为它真的特定于您的需求。 因此,如果jQuery可以处理点击,长按,移动等任何组合,那么需要维持数公里的代码和文档。

同样很难给你一个满足你需求的片段,但是setTimeout通常是第一步,有类似的东西:

obj.mouseup = function (){ obj.click = action; // do action setTimeout ( function() { obj.click = functionOrigin // after 500 ms, disable the click interception }, 500); };

There is nothing built-in because it's really specific to your needs. Thus, there would kilometers of code and documentation to maintain if jQuery would handle any combination of clicks, long clicks, moves, etc.

It's also hard to give you a snippet that satisfies your needs, but a setTimeout is usually the first step to take, with something like that :

obj.mouseup = function (){ obj.click = action; // do action setTimeout ( function() { obj.click = functionOrigin // after 500 ms, disable the click interception }, 500); };

更多推荐

本文发布于:2023-07-04 10:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1023554.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:是否会   如何判断   事件   jquery   mouseup

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!