来源于:

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.

随机推荐

  1. Machine Learning Algorithms Study Notes(3)--Learning Theory

    Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 本系列文章是Andrew Ng 在斯坦福的机器学习课程 CS 22 ...

  2. u3d单词学习plane

    plane n.水平: 平面: 飞机: 木工刨

  3. 关于log4j的讨论

    1.LoggersLoggers组件在此系统中被分为五个级别:DEBUG.INFO.WARN.ERROR和FATAL.这五个级别是有顺序的,DEBUG < INFO < WARN < ...

  4. JavaScript语言精粹笔记

    JavaScript语言精粹笔记 掌握语言的每个特性可以让你出风头,但是并不推荐,因为一部分的特性带来的麻烦可能远超本身的价值.正如书中所言,坏的材料并不能雕刻出好的作品,要成为一名更好的程序员,要取 ...

  5. [No000045]最好的休息,不是睡觉!

    导读 有人曾说,累,一定是你打开生活的方式不对.细细揣摩,很有道理,在这个世上,从来都是微笑不累,生气累:单纯不累,复杂累:相思不累,单恋累:相守不累,独守累:相爱不累,相残累:专情不累,滥情累:友情 ...

  6. 实用js函数收集

    1. 全选复选框: //复选框全选函数 function SelectAll() { var checkAll = document.getElementsByName("checkAll& ...

  7. Oracle Delete inner的方式,级联删除子表的数据方式。

    例子1: from table2 b where a.id=b.id) 例子2: rebatepolicy表是主表,rebatepolicyitems是从表,从表有主表的主键,现在对于主表一些条件的数 ...

  8. 自己封装的操作DOM方法

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. DOM操作基础

    ownerDocument 返回元素的 ownerDocumentoffsetParent 获取父节点(找有定位的父节点,没有定位默认是body,ie7以下定位在自己是html)parentNode ...

  10. Debian 8(Jessie) 安装pptp-linux (PPTP客户端), 以及route命令说明

    命令, 这里定义这个pptp的连接名称为hcoffice #安装 sudo apt-get install pptp-linux #用户名和口令 sudo vim /etc/ppp/chap-secr ...