jQuery的unbind()函数详解
2010-06-07 19:53:21.0
jQuery的绑定事件非常方便,有bind、unbind、live、one,还有它帮你把一些常用的事件给单独了出来,比如控件的onclick事件,我们绑定onclick事件的时候只需要
$("#testButton").click(function() {
alert("I'm Test Button");
});详细的可以参考我写过的jQuery事件机制
jQuery的绑定事件非常方便,有bind、unbind、live、one,还有它帮你把一些常用的事件给单独了出来,比如控件的onclick事件,我们绑定onclick事件的时候只需要
$("#testButton").click(function() {
alert("I'm Test Button");
});详细的可以参考我写过的jQuery事件机制
jQuery如何重新绑定已经绑定的事件?虽然我们现在推荐行为分离,渐进增强,但在很多遗留系统里还是存在很多这样的代码
<input type="button" value="ClickMe" id="btn1" onclick="foo()" />
就是直接在DOM元素上绑定事件
这样做有很多缺点
1.代码高度耦合
2.增加HTML大小
3.书写不了逻辑性很强的代码
bind:function (type, data, fn) {
return type == "unload" ? this.one(type, data, fn) : this.each(function () {
jQuery.event.add(this, type, fn || data, fn && data);
/