js动态加载js文件

try{
		function __loadJs(jsFile,callBack){
			var new_element = document.createElement("script");
			new_element.setAttribute("type", "text/javascript");
			new_element.setAttribute("src", jsFile);
			document.head.appendChild(new_element);
			new_element.onload=function(){
				if(typeof callBack == "function"){
				    callBack();
				//test2();
			 }
			}
		}
		//引入js
		__loadJs('http://my.test.com/test2.js');
		__loadJs('http://my.test.com/test2.js',function(){ test2();});
	}catch(e){
		alert("js加载失败"+e);
	} 
	

  


posted @ 2019-08-29 16:14  祥子zzz  阅读(246)  评论(0)    收藏  举报