Accessing functions bound to event handlers with jQuery

后端 未结 2 1753
逝去的感伤
逝去的感伤 2020-11-28 04:42

With jQuery you can bind functions to an event triggered on a DOM object using .bind() or one of the event handler helper functions.

jQuery have to stor

2条回答
  •  自闭症患者
    2020-11-28 05:05

    Edit: the method below works only in jQuery < 1.7

    You can find a lot of interesting tips and tricks in this article: Things you may not know about jQuery.

    It seems that jQuery uses data to store event handlers:

    You can access all event handlers bound to an element (or any object) through jQuery’s event storage:

    // 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['handler'].toString() );
        });
    });
    
    // You can see the actual functions which will occur
    // on certain events; great for debugging!
    

提交回复
热议问题