能动态加载js的步骤

能动态加载js的方法

  1. //加载新的js  
  2. function _GetJsData(url, callback) {  
  3.     var scripts = document.createElement("script");  
  4.     document.body.appendChild(scripts);  
  5.   
  6.     scripts.onload = function() {  
  7.         callback();  
  8.         document.body.removeChild(this);  
  9.     };  
  10.     scripts.onreadystatechange = function() {  
  11.         if (this.readyState == "loaded") {  
  12.             callback();  
  13.             document.body.removeChild(this);  
  14.         }  
  15.     };  
  16.     scripts.charset = "GBK";  
  17.     scripts.src = url;  
  18. }  
  19. _GetJsData('http://www.uefirst.com/index.js',isok);  
  20. var isok=function(){alert('isok')};