jQuery 1.8 find event handlers

北慕城南 提交于 2019-11-26 08:24:35

问题


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(\'events\') is undefined

回答1:


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/




回答2:


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")



来源:https://stackoverflow.com/questions/12214654/jquery-1-8-find-event-handlers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!