This is the code for the click
method:
jQuery.fn.click = function (data, fn) {
if (fn == null) {
fn = data;
data = null;
}
return arguments.length > 0 ? this.on("click", null, data, fn) : this.trigger("click");
}
as you can see; if no arguments are passed to the function it will trigger the click event.
Using .trigger("click")
will call one less function.
And as @Sandeep pointed out in his answer .trigger("click")
is faster:
As of 1.9.0 the check for data
and fn
has been moved to the .on
function:
$.fn.click = function (data, fn) {
return arguments.length > 0 ? this.on("click", null, data, fn) : this.trigger("click");
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…