jQuery上的trigger('click')和click()有什么区别 [英] What's the difference between trigger('click') and click() on jQuery

查看:572
本文介绍了jQuery上的trigger('click')和click()有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找两者之间的性能差异,在SSE中找不到关于此主题的好答案.

I'm looking for the difference in performance between those two, I could not found in SSE no good answer about this topic.

一些例子会很有帮助.

推荐答案

如果您查看jQuery代码,您会发现click()的全部工作是执行trigger('click'):

If you look at the jQuery code you can see that all click() does is execute trigger('click'):

jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
"mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
"change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {

// Handle event binding
jQuery.fn[ name ] = function( data, fn ) {
    if ( fn == null ) {
        fn = data;
        data = null;
    }

    return arguments.length > 0 ?
        this.on( name, null, data, fn ) :
        this.trigger( name );
};

请注意:

    return arguments.length > 0 ?
        this.on( name, null, data, fn ) :
        this.trigger( name );

换句话说,如果没有参数传递给click,请执行trigger('click')".

In other words, "If no arguments are passed to click, execute trigger('click')".

这篇关于jQuery上的trigger('click')和click()有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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