Home > Web Front-end > JS Tutorial > body text

JQuery1.8 Method to determine whether an element is bound to an event_jquery

WBOY
Release: 2016-05-16 16:42:07
Original
1075 people have browsed it

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

It probably means that the version can use obj.data('event'); JQuery1.8 version canceled the obj.data method and changed it to the $._data method

Note: obj[0] in $._data(obj[0],"event") must be added with the array[0] subscript, otherwise the data will not be obtained
-------The following are examples

<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>
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template