来源于:
The window.onload event fires when a document is completely downloaded to the
browser. This means that every element on the page is ready to be manipulated by
JavaScript, which is a boon for writing feature-rich code without worrying about
load order.
On the other hand, a handler registered using $(document).ready() is invoked
when the DOM is completely ready for use. This also means that all elements are
accessible by our scripts, but does not mean that every associated file has been
downloaded. As soon as the HTML file has been downloaded and parsed into a
DOM tree, the code can run.
Consider, for example, a page that presents an image gallery; such a page may have
many large images on it, which we can hide, show, move, and otherwise manipulate
with jQuery. If we set up our interface using the onload event, users will have to
wait until each and every image is completely downloaded before they can use those
features. Even worse, if behaviors are not yet attached to elements that have default
behaviors (such as links), user interactions could produce unintended outcomes.
However, when we use $(document).ready() for the setup, the interface is ready
to be used earlier with the correct behavior.
随机推荐
-
【腾讯bugly干货分享】HTML 5 视频直播一站式扫盲
本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://bugly.qq.com/bbs/forum.php?mod=viewthread&tid=1277 视频直 ...
-
提高Axure设计效率的10条建议
http://www.woshipm.com/ucd/92153.html Axure 是创建软件原型的快速有力的工具.上手很容易,但是,其中存在一个危险.这款软件是如此的直观以至于很多用户可以在没有 ...
-
记录自己在使用Bootstrap中的心得
一.网格系统 在做CRM OP后台时,直接在前人的的一些页面上进行了修改和增加,发现一些东西增加字段后有问题,比如网格系统,怎么改样式都不对,最后自己没法发,做成了半响应式的了.今天重新看Bootst ...
-
PostgreSQL中美元符号引用的字符串常量
虽然用于指定字符串常量的标准语法通常都很方便,但是当字符串中包含了很多单引号或反斜线时很难理解它,因为每一个都需要被双写.要在这种情形下允许可读性更好的查询,PostgreSQL提供了另一种被称为“美 ...
-
CMD命令窗口复制与粘贴
cmd命令提示符窗口中快速复制粘贴的方法常规方法 在“命令提 示符”窗口的任意一处,点击右键,在弹出的快捷菜单中选择“标记”命令. 此时在窗口的左上角处闪烁着一个长方块状的光标,将鼠标移动到希望复制的 ...
-
ASP.NET Core - Razor 页面简介
简介 随着ASP.NET Core 2 即将来临,最热门的新事物是Razor页面.在之前的一篇文章中,我们简要介绍了ASP.NET Core Razor 页面. Razor页面是ASP.NET Cor ...
-
ApplicationHost.config(IIS存储配置区文件)
对于一个刚刚创建网站,以ASP.NET MVC5为例. 我们并没有在网页的配置文件(web.config)中配置一些处理程序或模块,如处理Session的SessionStateModule模块,映射 ...
-
POM文件详解(2)
1 项目构建 <!-- 构建项目需要的信息 --> <build> <!-- 子项目可以引用的默认插件信息.该插件配置项直到被引用时才会被解析或绑定到生命周期. ...
-
Netflix开源类库archaius(一)概述
archaius是什么,能做什么? archaius是Netflix公司开源项目之一,基于java的配置管理类库,主要用于多配置存储的动态获取.主要功能是对apache common configur ...
-
whmcs模板路径
whmcs网站根目录 比如你的域名是server.nongbin.vip,你需要cd /home/wwwroot/server.nongbin.vip,该目录下然后,cd template/ 给文件夹 ...