jq源码-事件机制1

事件绑定接口有: bind, unbind, delegate,undelegate, on, one, off, trigger, triggerHandler.

以click例 :

1
2
3
4
5
jQuery.fn[ 'click' ] = function( data, fn ) {
return arguments.length > 0 ?
this.on( name, null, data, fn ) :
this.trigger( name );
};

bind方式

1
2
3
bind: function( types, data, fn ) {
return this.on( types, null, data, fn )
}

同样调用的this.on/this.off。
delegate方式

1
2
3
delegate: function( selector, types, data, fn ) {
return this.on( types, selector, data, fn )
}

one方式

1
2
3
one: function( types, selector, data, fn ) {
return this.on( types, selector, data, fn, 1 )
}