jQuery 1.8 find event handlers

后端 未结 2 1821
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 12:09

How to find event handlers on an object in jQuery 1.8+?

var func = function(){ alert(1); };
var obj = $(\'#obj\');
obj.on(\"click\", func);
// obj.data(\'eve         


        
相关标签:
2条回答
  • 2020-11-28 12:39

    Use the data function as is done by jQuery internally.

    On previous versions, you could call it like for other data :

    obj.data('events');
    

    In jQuery 1.8, this direct access was removed, so in recent versions you must call it like this :

    $._data(obj[0], "events")
    

    You can see it in action by opening the console in this fiddle : http://jsfiddle.net/8TpeP/2/

    0 讨论(0)
  • 2020-11-28 12:47

    to find event handlers of an element in jQuery 1.8+ you've got to do this way:

    $._data($("YOUR-SELECTOR-HERE").get(0), "events")

    0 讨论(0)
提交回复
热议问题