jQuery: $().click(fn) vs. $().bind(#39;click#39;,fn);(jQuery: $().click(fn) 与 $().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);
除了绑定的可选数据参数.
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);的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:jQuery: $().click(fn) 与 $().bind('click',fn);
基础教程推荐
- Bootstrap 模态出现在背景下 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
