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 Selectors(選擇器)的使用(二、層次篇)
本系列文章主要講述jQuery框架的選擇器(Selectors)使用方法,我將以實例方式進(jìn)行講述,以簡單,全面為基礎(chǔ),不會涉及很深,我的學(xué)習(xí)方法:先入門,后進(jìn)階!2009-12-12jQuery獲得頁面元素的絕對/相對位置即絕對X,Y坐標(biāo)
jQuery獲得頁面元素的絕對X,Y坐標(biāo),可以用offset()方法,下面有個不錯的坐標(biāo)大家可以參考下2014-03-03Jquery和angularjs獲取check框選中的值的方法匯總
本文分別通過具體的實例向大家展示了jquery和angularjs獲取獲取check框選中的值的方法,非常的簡單實用,有需要的小伙伴可以參考下2016-01-01ASP.NET jQuery 實例14 在ASP.NET form中校驗時間范圍
這節(jié)主要講如何用jQuery校驗表單時間范圍,時間控件用到了jQuery-ui2012-02-02cookie的復(fù)制與使用記住用戶名實現(xiàn)代碼
正如標(biāo)題所言cookie如何復(fù)制、使用與記住用戶名,下面有個不錯的示例,感興趣的朋友可以參考下2013-11-11