jQuery.getScript加载同域JS的代码
时间:2021-03-15 09:49:12|栏目:jquery|点击: 次
解决方法,用以下方法加载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);
};
上一篇:用jquery实现学校的校历(asp.net+jquery ui 1.72)
栏 目:jquery
本文标题:jQuery.getScript加载同域JS的代码
本文地址:http://www.codeinn.net/misctech/80880.html