1 function loadScript(src,callback){ 2 //生成新script 3 var newScript = document.createElement('script'); 4 newScript.type = 'text/javascript'; 5 if(window.attachEvent){ 6 newScript.src = src + (new Date().getTime()); 7 }else{ 8 newScript.src = src; 9 } 10 document.getElementsByTagName('head')[0].appendChild(newScript); 11 12 //判断是否加载完成 13 if(window.attachEvent){//ie 14 newScript.onreadystatechange = function(){ 15 if( !this.readyState || this.readyState == "loaded" || this.readyState == "complete" ){ 16 newScript.onreadystatechange = null; 17 if( callback && typeof callback === 'function' ){ callback() } 18 } 19 } 20 }else{ 21 newScript.onload = function(){ 22 newScript.onload = null; 23 if( callback && typeof callback === 'function' ){ callback() } 24 } 25 } 26 }