Skip to content

Instantly share code, notes, and snippets.

@caok
Created January 17, 2014 13:00
Show Gist options
  • Save caok/8472990 to your computer and use it in GitHub Desktop.
Save caok/8472990 to your computer and use it in GitHub Desktop.
window.onload
必须等待网页中所有的内容加载完毕后(包括图片)才能执行
不能同时编写多个,比如:
window.onload = function() {
alert("111");
};
window.onload = function() {
alert("222");
};
结果只会输出“222”
$(document).ready()
网页中所有DOM结构绘制完毕后就执行,可能DOM元素关联的东西并没有加载完
能同时编写多个,比如:
$(document).ready(function(){
alert("111");
});
$(document).ready(function(){
alert("222");
});
结果两次都输出
$(document).ready(function(){
//....
});
可以简写成:
$(function(){
//...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment