js 依次加载脚本
作者:互联网
function loadScript(url, callback) { var script = document.createElement("script") script.type = "text/javascript"; if (script.readyState) { //IE script.onreadystatechange = function () { if (script.readyState == "loaded" || script.readyState == "complete") { script.onreadystatechange = null; callback(); } }; } else { script.onload = function () { callback(); }; } script.src = url; document.getElementsByTagName("head")[0].appendChild(script); }; loadScript("file3.js", function () { loadScript("file1.js", function () { loadScript("file2.js", function () { console.log("All files are loaded!"); }); }); });
jq:
$.getScript();
$.getScript("test.js",function(){ setTimeout(function(){ alert(2) },2000) })
标签:function,readyState,script,js,callback,依次,loadScript,加载 来源: https://www.cnblogs.com/justSmile2/p/10768279.html