jQuery.getScript加载同域JS的代码
人气:0
解决方法,用以下方法加载js:
var loadScript = function(url, callback, charset){
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
if(charset){
script.charset = charset;
}
script.src = url;
if(!callback){
return;
}
script.onload = script.onreadystatechange = function(){
if(!this.readyState || this.readyState==='loaded' || this.readyState==='complete'){
callback();
}
};
head.appendChild(script);
};
复制代码 代码如下:
var loadScript = function(url, callback, charset){
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
if(charset){
script.charset = charset;
}
script.src = url;
if(!callback){
return;
}
script.onload = script.onreadystatechange = function(){
if(!this.readyState || this.readyState==='loaded' || this.readyState==='complete'){
callback();
}
};
head.appendChild(script);
};
加载全部内容