其他分享
首页 > 其他分享> > js判断异步js加载完毕

js判断异步js加载完毕

作者:互联网

let j = d.createElement('script'); j.async = true; j.src ='js地址'; if (typeof callback === "function") { if (typeof document.attachEvent !== "object") { j.onload = function () { callback(); // 回调函数调用 }; } else { j.onreadystatechange = function () { var r = j.readyState; if (r === "loaded" || r === "complete") { j.onreadystatechange = null; callback(); // 回调函数调用 } }; } } d.body.appendChild(j);

标签:function,异步,函数调用,js,callback,typeof,onreadystatechange,加载
来源: https://www.cnblogs.com/zerofan/p/15523178.html