JQuery1.8 is a way to determine whether an element is bound to an event

  • 2020-03-30 03:32:22
  • OfStack

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 while forming (obj [0], "events")

Version can use obj.data('event'); The obj.data method is dropped in query1.8 and replaced with the $._data method

Note :$._data(obj[0],"event") in the obj[0], be sure to add the array [0] index, otherwise the data will not get
-- the following is an example


<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 () {


//Determines whether the click event is bound
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=" Test whether the event is bound " />
<input type="button" id="btnTest" value=" Tested button " />
</body>
</html>


Related articles: