码迷,mamicode.com
首页 > Windows程序 > 详细

html中defer和window.onload的加载顺序

时间:2018-06-15 16:17:18      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:name   顺序   技术   func   meta   icon   alt   外部   att   

技术分享图片

结论:defer执行的顺序先于window.onload!

案例:

html代码:

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 
 4 <head>
 5     <meta charset="UTF-8">
 6     <meta name="viewport" content="width=device-width, initial-scale=1.0">
 7     <meta http-equiv="X-UA-Compatible" content="ie=edge">
 8     <title>Document</title>
 9     <link rel="shortcut icon" href="sources/images/Image1.png" type="image/x-icon">
10 </head>
11 <script defer="defer">
12     window.onload = function () {
13         alert(22dsed);
14         var oInput=document.getElementById(input1);
15     oInput.value=arr.length.toString();
16     }
17 
18     // oInput.setAttribute(value,arr.length.toString());
19 </script>
20 <script defer="defer" src="js/test.js"></script>
21 
22 
23 <body>
24     <input type="text" name="测试框" id="input1">
25 </body>
26 
27 </html>

外部js代码:

1     var arr=new Array();
2     arr.push(1);
3     arr.push(‘slj‘);
4     var oInput=document.getElementById(‘input1‘);
5     oInput.value=arr.length.toString();
6     alert(‘js运动01.html‘);

 

html中defer和window.onload的加载顺序

标签:name   顺序   技术   func   meta   icon   alt   外部   att   

原文地址:https://www.cnblogs.com/wdbim/p/9186716.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!