动态加载javascript脚本代码
关键字: javascript
/*
@param src
加载的脚本地址
@param callback
加载成功的执行脚本
@param charset
脚本字符编码
*/
function load(src, callback, charset) {
var script = document.createElement('script');
script.setAttribute('language', 'javascript');
if (charset) {
script.setAttribute('charset', charset);
}
script.setAttribute('type', 'text/javascript');
script.setAttribute('defer', '');
script.setAttribute('src', src);
document.getElementsByTagName("head")[0].appendChild(script);
if(document.all) {
script.onreadystatechange = function() {
if(this.readyState == 4 || this.readyState == 'complete' || this.readyState == 'loaded') {
callback();
}
};
} else {
script.onload = function() {
callback();
};
}
}
关键字: javascript
/*
@param src
加载的脚本地址
@param callback
加载成功的执行脚本
@param charset
脚本字符编码
*/
function load(src, callback, charset) {
var script = document.createElement('script');
script.setAttribute('language', 'javascript');
if (charset) {
script.setAttribute('charset', charset);
}
script.setAttribute('type', 'text/javascript');
script.setAttribute('defer', '');
script.setAttribute('src', src);
document.getElementsByTagName("head")[0].appendChild(script);
if(document.all) {
script.onreadystatechange = function() {
if(this.readyState == 4 || this.readyState == 'complete' || this.readyState == 'loaded') {
callback();
}
};
} else {
script.onload = function() {
callback();
};
}
}