大家好!我叫戴向天
QQ群:602504799
QQ:809002582
如若有不理解的,可加QQ群进行咨询了解
function introduceFile( param ){
param = param || {};
if(param.url){
if(param.type == "script" ||param.type === "js"){
let _script = document.createElement('script');
_script.setAttribute('src',param.url);
_script.setAttribute('type','text/javascript');
document.querySelector('head').appendChild(_script);
let Browser = this.browser();
if(Browser.ie){
_script.onreadystatechange=function(){
(this.readyState=='loaded'||this.readyStaate=='complete') && param.callBack && param.callBack(true) || param.callBack && param.callBack(false);
};
}else if(Browser.moz){
_script.onload=function(){
param.callBack && param.callBack(true);
};
_script.onerror = function(){
param.callBack && param.callBack(false);
}
}else{
param.callBack && param.callBack();
}
}else if(param.type == "style" ||param.type === "css"){
let _style = document.createElement('link');
_style.setAttribute("rel", "stylesheet");
_style.setAttribute("type", "text/css");
_style.setAttribute("href", param.url);
document.querySelector('head').appendChild(_style);
_style.onload = function(){
param.callBack && param.callBack(true)
}
_style.onerror = function(){
param.callBack && param.callBack(false)
}
}
}else{
console.log('请输入引入文件的地址')
}
return this;
}