jquery查看元素是否绑定事件的方法:1、以前版本可以使用【obj.data('event'); 】方法;2、JQuery1.8版本取消了【obj.data】方法,改为【$._data】方法。

本教程操作环境:windows7系统、jquery1.8版本,Dell G3电脑。
jquery查看元素是否绑定事件的方法:
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")
以前版本可以使用obj.data('event'); JQuery1.8版本取消了obj.data方法,改为$._data方法
注意:$._data(obj[0],"event")中的obj[0],一定要加上数组[0]下标,否则会取不到数据
-------以下为举例
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="/jquery-easyui-1.3.2/jquery-1.8.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#btnTest").click(function () { alert('aa'); });
$("#btn").click(function () {
//判断是否绑定了click事件
var objEvt = $._data($("#btnTest")[0], "events");
if (objEvt && objEvt["click"]) {
//console.info(objEvt["click"]);
alert("bind click");
}
else {
alert("Not bind click");
}
});
});
</script>
</head>
<body>
<input type="button" id="btn" value="测试是否绑定事件" />
<input type="button" id="btnTest" value="被测试按钮" />
</body>
</html>相关学习推荐:javascript视频教程
以上就是jquery如何查看元素是否绑定事件的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号