jQuery: $().click(fn) vs. $().bind('click',fn);

前端 未结 7 1781
北荒
北荒 2020-11-28 03:37

When using jQuery to hookup an event handler, is there any difference between using the click method

$().click(fn)

versus using the bind me

7条回答
  •  情歌与酒
    2020-11-28 03:58

    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)
    

    calls

    $().bind('click',fn)
    

提交回复
热议问题