2011-10-17 30 views
1

我有一个<a>标签并绑定到它两个事件。我如何获得有关其他事件的信息?如何获取有关通过live()绑定到元素的事件的信息?

后续的代码说明我的意思:

<a href="#" id="sample" class="sample-cls">Click me</a> 

$(function(){ 
    $('#sample').live("click", function(){ 
     sampleFunction(); 
    }) 
    $('.sample-cls').live("click", function(){ 
     // How to get information that to this link 
     // is attached another event, that run sampleFunction() ? 
    }) 
}) 

不幸的是,$('#sample').data('events')不包括通过live()绑定的事件。

回答

1
// List bound events: 
console.dir(jQuery('#elem').data('events')); 

// Log ALL handlers for ALL events: 
jQuery.each($('#elem').data('events'), function(i, event){ 
    jQuery.each(event, function(i, handler){ 
     console.log(handler.toString()); 
    }); 
}); 

this

当然,这可以进一步加强,以满足您的需求。

+0

我不认为这将在事件与问题中的“live”绑定时起作用。 –

+0

这就是我对此创建的新问题;)此代码返回一个“未定义” –

相关问题