简体   繁体   English

我可以在页面上声明jQuery的文档就绪函数多少次?

[英]How many times can I have jQuery's document ready function declared on a page?

How many times is it permitted to have the jQuery document ready function declared on a page, ie: 允许在页面上声明jQuery文档就绪函数的次数,即:

$(function () { ... });

or 要么

$(document).ready(function () { ... });

Is there any difference between the two? 这两者有什么区别吗?

If it's permitted more than one, do they fire in order of declaration? 如果允许不止一个,它们是否按照声明的顺序开火?

One: There is no difference between the two. 一:两者没有区别。

Quote: 引用:

All three of the following syntaxes are equivalent:

$(document).ready(handler)
$().ready(handler) (this is not recommended)
$(handler)

Two : You can have as many of them as you wish, and they will be executed in the order that the $() or $(document).ready() functions are executed. :你可以拥有任意数量的它们,它们将按照执行$()$(document).ready()函数的顺序执行。 (ie each handler is added to the queue) (即每个处理程序都添加到队列中)

As many as you need. 尽可能多的你需要。

The document ready function adds to what is essentially an event queue - the functions in these declarations will all be executed, either at the document.ready event, or immediately if that event has already fired, in order of declaration. 文档就绪函数添加到本质上是一个事件队列 - 这些声明中的函数将全部在document.ready事件中执行,或者如果该事件已经触发,则按声明顺序执行。

As many times as you like. 你喜欢多次。 They fire in order of declaration. 他们按照声明的顺序开火。

$(document).ready() will fire when the document is ready (when it's all loaded by the browser). $(document).ready()将在文档准备就绪时触发(当浏览器全部加载时)。 The other one will fire as soon as that part of the script executes. 一旦脚本执行该部分,另一个将立即触发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM