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);
posted @ 2021-11-08 10:53  吃饭七分饱  阅读(309)  评论(0编辑  收藏  举报