Skip to content

Instantly share code, notes, and snippets.

@foru17
Created April 3, 2014 06:33
Show Gist options
  • Save foru17/9949304 to your computer and use it in GitHub Desktop.
Save foru17/9949304 to your computer and use it in GitHub Desktop.
/**异步加载JS的方法*/
/**异步加载JS的方法*/
function loadJS(url,callback,el){
var isIE = !!window.ActiveXObject,
isIE6 = isIE && !window.XMLHttpRequest,
script = document.createElement("script"),
head = isIE6 ? document.documentElement : document.getElementsByTagName("head")[0];
script.type = "text/javascript";
script.async = true;
if(script.readyState){
script.onreadystatechange=function(){
if(script.readyState=="loaded"||script.readyState=="complete"){
script.onreadystatechange = null;
if (callback) {
callback();
}
}
}
}else{
script.onload=function(){
if (callback) {
callback();
}
}
}
script.src = url;
if (el) {
document.getElementById(el).appendChild(script);
} else {
head.insertBefore(script, head.firstChild);
}
};
// try{
// loadJS("http://xxx/s?st=__dh&site=dh123&node=1234&snode=123");
// }catch(e){}
loadJS("js/jquery.js",function(){
loadJS("js/dome.js",function(){
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment