首页 > Windows开发 > 详细

window.onload

时间:2020-02-28 15:18:51      阅读:63      评论:0      收藏:0      [点我收藏+]
window.onload() 方法用于在网页加载完毕后立刻执行的操作,即当 HTML 文档加载完毕后,立刻执行某个方法。 
window.onload() 通常用于 <body> 元素,在页面完全载入后(包括图片、css文件等等)执行脚本代码。
技术分享图片
 1 <!DOCTYPE html>  
 2 <html>  
 3 <head>  
 4 <meta charset=" utf-8">  
 5 <title>测试</title>
 6 <style type="text/css">
 7 #bg{
 8     width:100px;
 9     height:100px;
10     background:blue;
11 }
12 </style>
13 </head>
14 <body>
15     <div id="bg"></div>
16 </body>
17 </html>
18 <script type="text/javascript">
19     window.onload=init();
20     init(){
21         alert("DOM加载完毕");
22     }
23 </script>
View Code

 

<!DOCTYPE html>  
<html>  
<head>  
<meta charset=" utf-8">  
<title>测试</title>
<style type="text/css">
#bg{
    width:100px;
    height:100px;
    background:blue;
}
</style>
</head>
<body>
    <div id="bg"></div>
</body>
</html>
<script type="text/javascript">
    window.onload=init();
    init(){
        alert("DOM加载完毕");
    }
</script>

 


window.onload

原文:https://www.cnblogs.com/zhang-wen-yu-blog/p/12377098.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!