2011-10-17 28 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

這就是我對此創建的新問題;)此代碼返回一個「未定義」 –

相關問題