JQuery1.8 判断元素是否绑定事件的方法
Onpreviousversions,youcouldcallitlikeforotherdata:
obj.data('events');
InjQuery1.8,thisdirectaccesswasremoved,soinrecentversionsyoumustcallitlikethis:
$._data(obj[0],"events")
大概的意思是版本可以使用obj.data('event');JQuery1.8版本取消了obj.data方法,改为$._data方法
注意:$._data(obj[0],"event")中的obj[0],一定要加上数组[0]下标,否则会取不到数据
-------以下为举例
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<scriptsrc="/jquery-easyui-1.3.2/jquery-1.8.0.min.js"type="text/javascript"></script>
<scripttype="text/javascript">
$(function(){
$("#btnTest").click(function(){alert('aa');});
$("#btn").click(function(){
//判断是否绑定了click事件
varobjEvt=$._data($("#btnTest")[0],"events");
if(objEvt&&objEvt["click"]){
//console.info(objEvt["click"]);
alert("bindclick");
}
else{
alert("Notbindclick");
}
});
});
</script>
</head>
<body>
<inputtype="button"id="btn"value="测试是否绑定事件"/>
<inputtype="button"id="btnTest"value="被测试按钮"/>
</body>
</html>热门推荐
10 诗词送行祝福语大全简短
11 新房开工吉日祝福语简短
12 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短