pageLoad,onload& $(文件)。就绪() [英] difference between pageLoad , onload & $(document).ready()

查看:96
本文介绍了pageLoad,onload& $(文件)。就绪()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更详细地了解pageLoad,onload和amp;之间的区别。 $(document).ready()

i need to know in more detail of what is the differences between pageLoad , onload & $(document).ready()

我找到了答案,但这对我来说并不清楚。
答案就像是

I found answer but that is not ver clear to me. the answer is like


就绪事件发生在加载HTML文档之后,而onload事件发生在以后,当所有内容(例如图像)也已加载。

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.

onload事件是DOM中的标准事件,而ready事件特定于jQuery。 ready事件的目的是它应该在文档加载后尽早发生,以便为页面中的元素添加功能的代码不必等待加载所有内容。

The onload event is a standard event in the DOM, while the ready event is specific to jQuery. 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 funcionality to the elements in the page doesn't have to wait for all content to load.

在加载HTML文档后,试图说准备事件的人发生
和onload事件发生在所有页面元素如图像等被加载之后。

the person trying to say ready event occurs after the HTML document has been loaded and onload event occur after all page element like image etc being loaded.

那么什么是HTML文档加载?我知道HTML文档加载意味着所有页面元素加载完成。

So what is HTML document load? I know HTML document load means all page element load complete.

dom准备好或加载意味着什么? HTML文档加载和放大之间有什么区别? dom load?
请通过示例让我理解。
谢谢

What does mean like dom is ready or loaded? What is the difference between HTML document load & dom load? Please make me understand with example. Thanks

推荐答案

我不知道你的意思是pageLoad,但这里有一些关于<$ c $的信息c> onload 和 $(文件).ready()

I don't know what you mean by pageLoad, but here's some info on onload and $(document).ready().

window.onload 当页面中的所有内容都加载完毕后触发。这意味着不仅加载了整个DOM,而且完全加载了任何链接的资源,如图像。因为这等待图像完成加载,有时需要很长时间才能触发 window.onload 。除非您真的需要等到图像加载完毕,否则您通常不需要等待很长时间才能开始运行修改页面或挂钩事件处理程序等的javascript ...

window.onload fires when everything in the page has finished loading. That means that not only the entire DOM is loaded, but any linked resources such as images are fully loaded. Because this waits for images to finish loading, it can sometimes take a long time to fire window.onload. Unless you really need to wait until images are finished loading, you do not generally want to wait this long to start running your javascript that modifies the page or hooks up event handlers, etc...

$(document).ready()是一个特定于jQuery的事件,一旦DOM准备好进行操作就会触发,但可能早在图像出现之前就会触发完成装载。在页面HTML中存在的所有对象都已被浏览器解析和初始化之后以及页面中的所有脚本都已加载之后,就会发生这种情况。在此事件发生时,可以安全地修改所有浏览器中的DOM。这甚至可能在某些浏览器中稍早或稍后发生,因为用于检测DOM安全加载的时间的机制因旧浏览器和新浏览器而异。

$(document).ready() is a jQuery-specific event that fires as soon as the DOM is ready for manipulation, but potentially long before images have finished loading. This occurs after all objects present in the page HTML have been parsed and initialized by the browser and after all scripts in the page have been loaded. At the moment of this event, it is safe to modify the DOM in all browsers. This even may occur a little earlier or later in some browsers as the mechanism for detecting when the DOM is safely loaded varies between older and newer browsers.

jQuery 1.6.x 的实现$(document).ready()在DOM准备就绪时使用了许多不同的检测机制。首选方法是在文档对象上触发 DOMContentLoaded 事件。但是,此事件仅受某些浏览器支持,因此它具有其他浏览器的回退机制。

The jQuery 1.6.x implementation for $(document).ready() uses a number of different detection mechanisms for when the DOM is ready. The preferred method is when the DOMContentLoaded event triggers on the document object. But, this event is only supported by some browsers so it has fallback mechanisms for other browsers.

这两个事件每个页面只会触发一次。

Both of these events will fire only once per page.

这篇关于pageLoad,onload&amp; $(文件)。就绪()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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