加载js脚本函数
2021-01-26 20:15
标签:style call back async code eve ret tno cti 加载单个js脚本 加载多个js脚本 加载js脚本函数 标签:style call back async code eve ret tno cti 原文地址:https://www.cnblogs.com/dmc-nero/p/13228644.html var loadSingleScript = function (src, callback) {
var s = document.createElement(‘script‘);
s.async = false;
s.src = src;
s.addEventListener(‘load‘, function () {
s.parentNode.removeChild(s);
s.removeEventListener(‘load‘, arguments.callee, false);
callback();
}, false);
document.body.appendChild(s);
};
var loadScript = function (list, callback) {
if (list.length ) {
callback()
return
}
var loaded = 0;
var startLen = 0
var loadNext = function () {
for (var i = 0; i i) {
var url = list[loaded++]
if (url) {
loadSingleScript(url, function () {
startLen++;
if (startLen >= list.length) {
callback();
}
else {
loadNext();
}
})
}
}
};
loadNext();
};