(function () {
xe = window.xe || {};
xe.load = {
filesAdded: {},
loadScript: function (src) {
if (this.filesAdded[src]) {
return 0;
}
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = src;
this.filesAdded[src] = true;
document.body.appendChild(script);
},
loadScriptString: function (code) {
var script = document.createElement('script');
script.type = 'text/javascript';
try {
script.appendChild(document.createTextNode(code));
} catch (ex) {
script.text = code;
}
document.body.appendChild(script);
},
loadCss: function (href) {
if (this.filesAdded[href]) {
return 0;
}
var link = document.createElement('link');
link.type = 'text/css';
link.rel = 'stylesheet';
link.href = href;
this.filesAdded[href] = true;
document.getElementsByTagName('head')[0].appendChild(link);
},
loadCssString: function (code) {
var style = document.createElement('style');
style.type = 'text/css';
try {
style.appendChild(document.createTextNode(code));
} catch (ex) {
style.styleSheet.cssText = code;
}
document.getElementsByTagName('head')[0].appendChild(style);
}
};
xe = window.xe || {};
xe.load = {
filesAdded: {},
loadScript: function (src) {
if (this.filesAdded[src]) {
return 0;
}
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = src;
this.filesAdded[src] = true;
document.body.appendChild(script);
},
loadScriptString: function (code) {
var script = document.createElement('script');
script.type = 'text/javascript';
try {
script.appendChild(document.createTextNode(code));
} catch (ex) {
script.text = code;
}
document.body.appendChild(script);
},
loadCss: function (href) {
if (this.filesAdded[href]) {
return 0;
}
var link = document.createElement('link');
link.type = 'text/css';
link.rel = 'stylesheet';
link.href = href;
this.filesAdded[href] = true;
document.getElementsByTagName('head')[0].appendChild(link);
},
loadCssString: function (code) {
var style = document.createElement('style');
style.type = 'text/css';
try {
style.appendChild(document.createTextNode(code));
} catch (ex) {
style.styleSheet.cssText = code;
}
document.getElementsByTagName('head')[0].appendChild(style);
}
};
})();
使用方法: xe.load.loadCss(csshref); //把样式地址给他它就行了