$(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.
随机推荐
- windows下nodejs环境配置
一.下载 去nodejs下载node.msi安装文件包,里面包含了node.js和npm: 双击node.msi就行了,选择安装路径和npm: 二.设置环境变量 [新版本都不需要设计环境变量了,软件会 ...
- [PHP]swoole_server几个进程的分工
readme.md-/Users/zjh/Documents/我的文章/[PHP]swoole_server几个进程的分工 html{font-family: sans-serif;-ms-text- ...
- apache poi导出excel报表
Apache POI 是用Java编写的免费开源的跨平台的 Java API,Apache POI提供API给Java程式对Microsoft Office格式档案读和写的功能.POI为"P ...
- Android中事件传递机制的总结
事件传递虽然算不上某个单独的知识点,但是在实际项目开发中肯定会碰到,如果不明白其中的原理,那在设计各种滑动效果时就会感到很困惑. 关于事件的传递,我们可能会有以下疑问: 事件是如何传递的 事件是如何处 ...
- Maven学习(三)生命周期
maven有三套生命周期 1.clean 清理项目 2.default 构建项目 3.site 建立项目站点 每套生命周期都包含了一些阶段,这些阶段是有序的,后 ...
- Zygote进程【2】——Zygote的分裂
在Zygote的诞生一文中init进程是如何一步步创建Zygote进程的,也了解了Zygote的进程的作用.Zygote进程的诞生对于整个Java世界可以说有着"开天辟地"的作用, ...
- github上写blog
http://www.elbow95.me/blog/My-First-Blog-Essay.html 阮一峰的: http://www.ruanyifeng.com/blog/2012/08/blo ...
- 资料,来自HTML5前端开发学习⑤群
resource HTML5+CSS3视频教程:http://pan.baidu.com/s/1hsyOjze 密码:c3uw JavaScript视频教程:链接:http://pan.baidu.c ...
- Debian 8(Jessie) 安装pptp-linux (PPTP客户端), 以及route命令说明
命令, 这里定义这个pptp的连接名称为hcoffice #安装 sudo apt-get install pptp-linux #用户名和口令 sudo vim /etc/ppp/chap-secr ...
- Java核心技术点之动态代理
本篇博文会从代理的概念出发,介绍Java中动态代理技术的使用,并进一步探索它的实现原理.由于个人水平有限,叙述中难免出现不清晰或是不准确的地方,希望大家可以指正,谢谢大家:) 一.概述 1. 什么是代 ...