本文介绍了jQuery中的jQuery()函数有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在中,有一段代码如下所示:

In this video there is a snippet of code that goes something like this:

if (jQuery) {jQuery(function() {
    // ...
})}

我从未见过 jQuery()之前的功能(然后再说,我不是一个精明的jQuery用户),它做了什么?它是默认使用jQuery发布的还是特定于?由于通常的 $(窗口).load()代码段丢失且代码有点相似,我猜它是一个快捷方式/别名:

I've never seen the jQuery() function before (then again, I'm not a savvy jQuery user), what does it do? Does it ship by default with jQuery or is it specific to IxEdit? Since the usual $(window).load() snippet is missing and the code is somewhat similar I'm guessing it's a shortcut / alias to:

$(window).load(function() {
    // ...
)}

我是对的吗?那个 jQuery 变量是什么?它有什么作用?他为什么要检查它?

Am I right? Also what is that jQuery variable? What does it hold? And why is he checking it?

推荐答案

$()是jQuery()的别名,定义为:

$() is an alias for jQuery(), defined as:

// Expose jQuery to the global object
window.jQuery = window.$ = jQuery;

有一个特殊情况定义为$( )或jQuery()被调用,第一个参数是函数:

there is a special case defined when $() or jQuery() is called with the first argument being a function:

// HANDLE: $(function)
// Shortcut for document ready
} else if ( jQuery.isFunction( selector ) ) {
    return rootjQuery.ready( selector );
}

有时$可以与定义相同功能的其他库(如原型)发生冲突,所以如果你打电话

sometimes $ can conflict with other libraries (like prototype) that define the same function, so if you call

jQuery.noConflict();

它会删除$别名,将其设置回原来的值,基本上是:

it will remove the $ alias, setting it back to the original value found, essentially:

window.$ = _$;

这篇关于jQuery中的jQuery()函数有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 11:01