快捷方法(例如.change()
)只是在bind
内部调用:
jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
"mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
"change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {
// Handle event binding
jQuery.fn[ name ] = function( data, fn ) {
if ( fn == null ) {
fn = data;
data = null;
}
return arguments.length > 0 ?
this.bind( name, data, fn ) : //Just call `bind`
this.trigger( name );
};
//...
并bind
简单地调用on
:
//...
bind: function( types, data, fn ) {
return this.on( types, null, data, fn ); //Just call `on`
},
//...
So it's probably very marginally quicker to just call on
yourself. In real terms, there will be no difference in speed, so just use the one you feel most comfortable with.