jQuery 1.8 查找事件处理程序 [英] jQuery 1.8 find event handlers

查看:21
本文介绍了jQuery 1.8 查找事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 jQuery 1.8+ 中找到对象的事件处理程序?

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

推荐答案

使用数据函数就像jQuery内部做的那样.

在以前的版本中,您可以像其他数据一样调用它:

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

obj.data('events');

在 jQuery 1.8 中,这个直接访问被删除了,所以在最近的版本中你必须这样称呼它:

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

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

您可以通过在此小提琴中打开控制台来查看它的运行情况:http://jsfiddle.net/8TpeP/2/

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

这篇关于jQuery 1.8 查找事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆