$(document).ready()和window.onload的区别
来源于:
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.
随机推荐
- Neutron VxLAN + Linux Bridge 环境中的网络 MTU
1. 基础知识 1.1 MTU 一个网络接口的 MTU 是它一次所能传输的最大数据块的大小.任何超过MTU的数据块都会在传输前分成小的传输单元.MTU 有两个测量层次:网络层和链路层.比如,网络层 ...
- Java:JSTL遍历数组,List,Set,Map
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- Eclipse调试Bug的七种常用技巧
1. 条件断点 断点大家都比较熟悉,在Eclipse Java 编辑区的行头双击就会得到一个断点,代码会运行到此处时停止. 条件断点,顾名思义就是一个有一定条件的断点,只有满足了用户设置的条件,代码才 ...
- NOIP2015跳石头[二分答案]
题目背景 一年一度的“跳石头”比赛又要开始了! 题目描述 这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石.组委会已经选 择好了两块岩石作为比赛起点和终点.在起点和终点之间,有 N 块岩石( ...
- Flex:自定义滚动条样式/隐藏上下箭头
Flex组件自定义滚动条的实现 .scrollBar{ downArrowUpSkin:Embed(source="img/mainLeftScrollBar/bar_bottom.png& ...
- Extjs API - JS Duck
1. 安裝JS Duck3 tar.gz版本 https://nodeload.github.com/senchalabs/jsduck/tarball/master exe版本 http://c ...
- Json转换类库
20160605 简单的DaTable转Json private string DtConvertJson(DataTable dt , string modelName="") ...
- EF的入门使用 (电影管理)
控制器代码: public class HomeController : Controller { private NewDBContext ndc = new NewDBContext(); pub ...
- 判断一个变量的类型Object.prototype.toString.call
var num = 1;alert(Object.prototype.toString.call(num)); // [object Number]var str = 'hudidit.com';al ...
- Java集合系列:-----------08HashMap的底层实现
对于HashMap感觉一直是看了忘,忘了看.这里就单独写一篇日志来记录一下.HashMap的底层实现. 非常好的讲HashMap的博客:http://blog.csdn.net/vking_wang/ ...