简体   繁体   English

区分同一元素上的两个不同的点击事件

[英]Differentiate between two different click events on same element

If I want to detect if a click event has been attached to an element, I can do the following: 如果要检测是否已将click事件附加到元素,可以执行以下操作:

function eventAlreadyBound($element){
    var boundEvents = $._data($element[0], 'events') || {};
    return boundEvents.hasOwnProperty('click');
}

If there's a click, returns true. 如果单击,则返回true。

Now, say two different plugins want to add click one click event to the same element. 现在,假设有两个不同的插件要向同一元素添加click一击事件。 If they both run the above check, then only the first plugin gets to apply its event. 如果它们都运行上述检查,则只有第一个插件可以应用其事件。

How could plugin B check to see if its own click has been applied while disregarding any click events applied by plugin A? 插件B如何忽略插件A施加的任何点击事件,查看自己的点击是否被应用?

Can I name events? 我可以命名活动吗? Attach ids to them? 附加ID给他们吗? Something else? 还有吗

You can attach custom events in jQuery. 您可以在jQuery中附加自定义事件。 They behave like normal events. 它们的行为就像正常事件。 Check out this guide - https://learn.jquery.com/events/introduction-to-custom-events/ 查阅本指南-https: //learn.jquery.com/events/introduction-to-custom-events/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM