标签:style call back async code eve ret tno cti
加载单个js脚本
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); };
加载多个js脚本
var loadScript = function (list, callback) { if (list.length < 1) { callback() return } var loaded = 0; var startLen = 0 var loadNext = function () { for (var i = 0; i < 10; ++i) { var url = list[loaded++] if (url) { loadSingleScript(url, function () { startLen++; if (startLen >= list.length) { callback(); } else { loadNext(); } }) } } }; loadNext(); };
标签:style call back async code eve ret tno cti
原文地址:https://www.cnblogs.com/dmc-nero/p/13228644.html