您的位置:首页 > Web前端 > JavaScript

js动态加载以及确定加载完成的代码

2018-10-12 13:55 417 查看
代码如下:

var otherJScipt = document.createElement("script");
otherJScipt = document.createElement("script");
otherJScipt.setAttribute("type", "text/javascript");
otherJScipt.setAttribute("src", "/xxx.js");
document.getElementsByTagName("head")[0].appendChild(otherJScipt);//追加到head标签内


//判断服务器
if (navigator.userAgent.indexOf("IE") >= 0) {
//IE下的事件
otherJScipt.onreadystatechange = function () {
//IE下的判断,判断是否加载完成
if (otherJScipt && (otherJScipt.readyState == "loaded" || otherJScipt.readyState == "complete")) {
otherJScipt.onreadystatechange = null;
callMyFun();
}
};
}
else {
otherJScipt.onload = function () {
otherJScipt.onload = null;
callMyFun();
};
}

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: