onload()和$ .ready之间的区别? [英] Difference between onload() and $.ready?

查看:151
本文介绍了onload()和$ .ready之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能列出 onload() $(文件).ready(function(){..})使用jQuery中的函数?

Can you list the difference between onload() and $(document).ready(function(){..}) functions in the using jQuery?

推荐答案

窗口上的加载事件(又名onload)和/或body元素将在 all 加载页面内容后触发 - 这包括所有图像,脚本等......一切。

the load event (a.k.a "onload") on the window and/or body element will fire once all the content of the page has been loaded -- this includes all images, scripts, etc... everything.

相比之下,jquery的 $(document).ready(...)函数将使用特定于浏览器的机制来确保尽快调用您的处理程序加载并访问HTML / XML dom后可能的。这是页面加载过程中最早的一点,您可以安全地运行打算访问页面的html dom中的元素的脚本。这一点比最终的 load 事件更早(通常更早)到达,因为加载辅助资源(如图像等)需要额外的时间。

In contrast, jquery's $(document).ready(...) function will use a browser-specific mechanism to ensure that your handler is called as soon as possible after the HTML/XML dom is loaded and accessible. This is the earliest point in the page load process where you can safely run script that intends to access elements in the page's html dom. This point arrives earlier (often much earlier) than the final load event, because of the additional time required to load secondary resources (like images, and such).

这篇关于onload()和$ .ready之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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