标签: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‘);
标签:name 顺序 技术 func meta icon alt 外部 att
原文地址:https://www.cnblogs.com/wdbim/p/9186716.html