我需要检查某些事件是否已绑定(bind)到元素上。
例如
$(".animate").click(function(){
alert('Here comes action');
});
和
$(".someOtherSelector").click(function(){
alert('some other action');
});
HTML
<a class="animate"></a>
<a class="someOtherSelector animate"></a>
在第二个函数中,我需要检查此元素上是否已绑定(bind)事件。如果是这样,则不应执行 alert('some other action');
。
我使用的是 jQuery 版本 1.10.1。
最佳答案
从jQuery 1.8开始,事件数据
不再适用于数据。阅读此jQuery blog post 。您现在应该使用这个:
jQuery._data(element, "events")
代码
$('.someOtherSelector').each(function(){
console.log($._data(this, "events"));
});
关于JQuery 检查事件绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19181398/