$('#btn').trigger('click');$('#btn').click();求教这两种 click 事件的触发方式选择哪种更优?
1 回答
Cats萌萌
TA贡献1805条经验 获得超9个赞
jquery2的源码
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 ) {
return arguments.length > 0 ?
this.on( name, null, data, fn ) :
this.trigger( name );
};
});
看起来,$对象的click执行事件实现也是调用trigger……所以trigger更优?
添加回答
举报
0/150
提交
取消