使用 jQuery 连接事件处理程序时,使用 click 方法有什么区别
When using jQuery to hookup an event handler, is there any difference between using the click method
$().click(fn)
相对于使用绑定方法
$().bind('click',fn);
除了绑定的可选数据参数.
Other than bind's optional data parameter.
对于它的价值,来自 jQuery 源码:
For what it's worth, from the jQuery source:
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)
通话
$().bind('click',fn)
这篇关于jQuery: $().click(fn) 与 $().bind('click',fn);的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!