在开发中遇到问题,需要在页面加载前显示广告提示。也就是在dom还没有加载先显示广告,当页面所有资源加载完后在隐藏广告,显示dom内容。window onload包含dom load。
页面响应加载的顺序是,域名解析->加载html->加载js和css->加载图片等其他信息,jquery的Dom Ready方法在加载图片等其他信息前就可以操作Dom了,先于window.onload事件触发前执行。
[color=red]Jquery的ready和Dom的onload的区别:
1. onload是所有dom元素创建完毕,图片、css等都加在完毕后才触发
2. ready则是dom元素创建完毕后就被触发
相对来说jquery的ready可以提高网页的响应速度.[/color]
参考:
[url]http://www.jsmix.com/javascript/document-ready-window-load.html[/url]
[url]http://xuxiangpan888.iteye.com/blog/253323[/url]
[url]http://www.css88.com/archives/2112[/url]
[url]http://www.61dh.com/blog/2009/01/jquery-documentready.html[/url]
[url]http://blog.suiyidian.cn/post-55.html[/url]
页面响应加载的顺序是,域名解析->加载html->加载js和css->加载图片等其他信息,jquery的Dom Ready方法在加载图片等其他信息前就可以操作Dom了,先于window.onload事件触发前执行。
[color=red]Jquery的ready和Dom的onload的区别:
1. onload是所有dom元素创建完毕,图片、css等都加在完毕后才触发
2. ready则是dom元素创建完毕后就被触发
相对来说jquery的ready可以提高网页的响应速度.[/color]
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>测试页面</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
document.open();
document.write('测试开始...............................');
document.close();
</script>
<script>
$(function(){
alert('DOM资源已经加载完成!');
})
</script>
</head>
<!--body onload IE浏览器支持-->
<body onload="alert('body on load!');">
<div id="content">
<div></div>
</div>
<script>
//绑定window.onload事件
window.onload = function(){alert('页面全部资源已经加载完成1');};
//重复绑定window.onload事件
$(window).load(function(){
alert('页面全部资源已经加载完成2');
});
document.write('测试结束...............................');
</script>
</body>
</html>
参考:
[url]http://www.jsmix.com/javascript/document-ready-window-load.html[/url]
[url]http://xuxiangpan888.iteye.com/blog/253323[/url]
[url]http://www.css88.com/archives/2112[/url]
[url]http://www.61dh.com/blog/2009/01/jquery-documentready.html[/url]
[url]http://blog.suiyidian.cn/post-55.html[/url]