function loadScripts(urls, callback) {
if (typeof (urls) === "string"){
urls = [urls];
}
var returnCallback = function (url) {
returnCallback.Counter++;
if (returnCallback.Counter >= urls.length){
callback();
}
}
returnCallback.Counter = 0;
var oHead = document.getElementsByTagName("head")[0];
for (var i = 0; i < urls.length; i++){
loadScript(urls[i], returnCallback,oHead);
}
} function loadScript(url, callback,oHead) {
var script = document.createElement("script")
script.type = "text/javascript";
script.src = url;
//IE6-8
if (script.readyState) {
script.onreadystatechange = function () {
if (script.readyState == "loaded" || script.readyState == "complete") {
script.onreadystatechange = null;
callback(url);
}
};
}
//ie9+,chrome,ff
else {
script.onload = function () {
callback(url);
};
}
oHead = oHead || document.getElementsByTagName("head")[0];
oHead.insertBefore( script, oHead.firstChild );
}
参考:http://www.cnblogs.com/aarond/category/504617.html
http://www.cnblogs.com/sntetwt/p/4075154.html