$(document).ready(function(){在JQuery中...担心覆盖?

Dan*_*ark 6 jquery onload

在JQuery中使用这个很酷的onload函数

$(document).ready(function(){ // my stuff }
Run Code Online (Sandbox Code Playgroud)

我是否需要担心覆盖其他任何可能称之为的内容?

One*_*erd 10

在jQuery中,该函数添加到我认为的就绪队列,因此您可以编写多个ready()函数,而不必担心覆盖以前的函数(它们只是堆栈).


awe*_*awe 2

@OneNerd的回答是正确的,它只是添加到就绪队列中。该ready方法在 jQuery 中声明如下:

ready: function( fn ) {
    // Attach the listeners
    jQuery.bindReady();

    // Add the callback
    readyList.add( fn );

    return this;
},
Run Code Online (Sandbox Code Playgroud)

参考: http: //code.jquery.com/jquery.js