Created
April 3, 2014 06:33
-
-
Save foru17/9949304 to your computer and use it in GitHub Desktop.
/**异步加载JS的方法*/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**异步加载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