有没有办法知道,在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); };更多推荐
发布评论