发布于 2016-10-16 09:06:45 | 126 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的jQuery示例,程序狗速度看过来!

jQuery javascript框架

jQuery是一个兼容多浏览器的javascript框架,核心理念是write less,do more(写得更少,做得更多)。jQuery在2006年1月由美国人John Resig在纽约的barcamp发布,吸引了来自世界各地的众多JavaScript高手加入,由Dave Methvin率领团队进行开发。


这篇文章主要介绍了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],一定要加上数组[0]下标,否则会取不到数据
-------以下为举例


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



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务