动态加载js

动态加载js

 

 1 function loadJs(jssrc, callback) {
 2         if (jssrc) {
 3             var head = document.getElementsByTagName(‘head‘)[0];
 4             var script = document.createElement(‘script‘);
 5             if (script.readyState) { //IE
 6                 script.onreadystatechange = function () {
 7                     if (script.readyState == "loaded" || script.readyState == "complete") {
 8                         script.onreadystatechange = null;
 9                         if (callback && typeof callback == ‘function‘) {
10                             callback();
11                         }
12                     }
13                 };
14             } else { //Others
15                 script.onload = function () {
16                     if (callback && typeof callback == ‘function‘) {
17                         callback();
18                     }
19                 }
20             }
21             script.src = jssrc;
22             head.appendChild(script);
23         }
24     }
View Code

 

 

动态加载js,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。