jQuery:$()。click(fn)vs. $()。bind('click',fn);
问题描述:
使用jQuery连接事件处理程序时,使用click方法是否有区别?
When using jQuery to hookup an event handler, is there any difference between using the click method
$().click(fn)
与使用绑定方法
$().bind('click',fn);
除bind的可选数据参数外。
Other than bind's optional data parameter.
答
对于什么值得,从 jQuery源:
jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
"mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave," +
"change,select,submit,keydown,keypress,keyup,error").split(","), function(i, name){
// Handle event binding
jQuery.fn[name] = function(fn){
return fn ? this.bind(name, fn) : this.trigger(name);
};
});
所以没有,没有区别 -
So no, there's no difference -
$().click(fn)
p>
calls
$().bind('click',fn)