Copy Code code as follows:
Dynamically loading external JS files
var flag = true;
if (flag) {
Loadscript ("Js/index.js");
};
function Loadscript (URL) {
var script = document.createelement ("script");
Script.type = "Type/javascipt";
script.src = URL;
document.getElementsByTagName ("Head") [0].appendchild (script);
};
Dynamically loading JS
if (flag) {
var script = document.createelement ("script");
Script.type = "Text/javascript";
Script.text = "";
document.getElementsByTagName ("Head") [0].appendchild (script);
};
Dynamically load external CSS styles
if (flag) {
Loadcss ("Css/base.css");
};
function loadcss (URL) {
var link = document.createelement ("link");
Link.type = "Text/css";
Link.rel = "stylesheet";
Link.href = URL;
document.getElementsByTagName ("Head") [0].appendchild (link);
};
Dynamically loading CSS Styles
if (flag) {
var style = document.createelement ("style");
Style.type = "Text/css";
document.getElementsByTagName ("Head") [0].appendchild (style);
var sheet = document.stylesheets[0];
Insertrules (sheet, "#gaga1", "Background: #f00", 0);
};
function Insertrules (sheet,selectortxt,csstxt,position) {
if (sheet.insertrule) {//Judge non IE browser
Sheet.insertrule (Selectortxt + "{" + Csstxt + "}", position);
}else if (sheet.addrule) {//determine if IE browser
Sheet.addrule (Selectortxt, csstxt, position)
}
}