1,
通过给script标签增加 defer属性或者是 async 属性来实现 <script src="file.js" defer></script> 注解: async和defer不同之处是async加载完成后会自动执行脚本,defer加载完成后需要等待页面也加载完成才会执行代码
2,
// 动态加载JS文件 function loadJS( url, callback ){ var script = document.createElement('script'),fn = callback || function(){}; script.type = 'text/javascript'; //IE if(script.readyState){ script.onreadystatechange = function(){if( script.readyState == 'loaded' || script.readyState == 'complete' ){script.onreadystatechange = null;fn();}}; }else{ script.onload = function(){fn();}; } script.src = url; document.getElementsByTagName('head')[0].appendChild(script); }; //用法 loadJS('http://oss.esunar.com/My_Code/Libs/CheckWXES.js',function(){});