且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery选择器jQuery("element")和$("element")之间有什么区别?

更新时间:2022-05-17 05:32:58

$只是对全局jQuery对象的简短引用.

$ is just a short reference to the global jQuery object.

window.$ === window.jQuery // true

大多数插件作者将美元符号放入自调用方法中,以确保美元符号确实在引用jQuery对象.

Most plugin authors make sure that the dollar sign really is referencing the jQuery object, by putting it into a self-invoking method.

(function( $ ) {
    // $(document)
}( jQuery ));

通过使用jQuery对象作为参数调用该匿名方法,我们可以通过$在该方法内访问它.

By invoking that anonymous method with the jQuery object as argument, we can access it within the method via $.