JQuery1.8 判斷元素是否綁定事件的方法
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],一定要加上數(shù)組[0]下標(biāo),否則會取不到數(shù)據(jù)
-------以下為舉例
<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>
相關(guān)文章
jQuery使用getJSON方法獲取json數(shù)據(jù)完整示例
這篇文章主要介紹了jQuery使用getJSON方法獲取json數(shù)據(jù),結(jié)合完整實例形式分析了getJSON方法讀取與遍歷json文件數(shù)據(jù)的相關(guān)技巧,需要的朋友可以參考下2016-09-09
用jquery統(tǒng)計子菜單的條數(shù)示例代碼
統(tǒng)計子菜單條數(shù)的方法有很多,在本文為大家詳細(xì)介紹下使用jquery是如何實現(xiàn)的,感興趣的朋友不要錯過2013-10-10
jquery scroll()區(qū)分橫向縱向滾動條的方法
這篇文章主要介紹了使用jquery scroll()方法區(qū)分瀏覽器橫向和縱向滾動條的方法,需要的朋友可以參考下2014-04-04

