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替换element元素上已经绑定的事件

2010-06-05 14:31:18.0

jQuery如何重新绑定已经绑定的事件?虽然我们现在推荐行为分离,渐进增强,但在很多遗留系统里还是存在很多这样的代码

<input type="button" value="ClickMe" id="btn1" onclick="foo()" />

就是直接在DOM元素上绑定事件

这样做有很多缺点

1.代码高度耦合

2.增加HTML大小

3.书写不了逻辑性很强的代码

jquery如何绑定事件

2010-05-28 14:58:37.0
对于注册事件,jquery提供了bind、one、toggle、hover四种注册事件的方法, bind是最基本的方法。One是注册 只运行一次的方法,toggle注册交替运行的方法。Hover是注册鼠标浮过的方法

1.2.6中bind的源代码:
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);
/