关于多个ready()的问题 [英] Question about multiple ready()'s

查看:88
本文介绍了关于多个ready()的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有:

<script src="script1.js"></script>
<script src="script2.js"></script>

这两个脚本都有 ready()内。 script2.js的 ready()中的代码是否总是在第一个之后执行?

Both of these scripts have ready() inside. Will the code in script2.js's ready() always execute after the first one?

推荐答案

是。

首先, script2.js 中的代码将在 script1之后执行。 js ,因为它在文档后面(以及 延期属性未设置。)

First of all, the code in script2.js will be executed after script1.js, as it comes later in the document (and the defer attribute is not set).

此外,实现 [source] < ready 函数的/ a>是:

Furthermore, the implementation [source] of the ready function is:

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

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

    return this;
},

其中 readyList 似乎 [来源] 延迟对象 [docs] 。这意味着回调按照它们添加到该对象的顺序执行。

where readyList seems to be [source] a deferred object [docs]. That means the callbacks are executed in the order they have been added to that object.

这篇关于关于多个ready()的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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