【jQuery】window.onload 和 $(document).ready() 的区别

2023-10-17 09:16:34 浏览数 (1)

...

在Stack Overflow上看到了这个问题,自己翻译了过来。


The onload event is a standard event in the DOM, while the ready event is specific to jQuery. 

window.onload 是DOM中的标准事件,而$(document).ready() 是jQuery中的事件。(显然......)


The ready event occurs after the HTML document has been loaded, while the onload event occurs later, when all content (e.g. images) also has been loaded.

当HTML document 载入完毕后,ready 事件发生。但是,onload 事件发生的比ready 更晚。当网页上所有的内容(content)载入完毕后(包括图片),onload 事件才会发生。


The purpose of the ready event is that it should occur as early as possible after the document has loaded, so that code that adds functionality to the elements in the page doesn't have to wait for all content to load.

ready 事件的目的是:在document 装载完成之后,ready 事件应该尽可能早的发生。以便于给elements 添加功能,而不用等所有的content 都装载完成。


...

0 人点赞