jQuery:$()。click(fn)vs. $()。bind('click',fn); [英] jQuery: $().click(fn) vs. $().bind('click',fn);

查看:151
本文介绍了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)

这篇关于jQuery:$()。click(fn)vs. $()。bind('click',fn);的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆