1. Loading required files in an external CSS file
@importurl (STYLE.CSS);
Can only be used in CSS files or in style labels
2. Simply load an external CSS file on the page
Document.createstylesheet (Cssfile);
2. Create a CSS link tag with the CreateElement method
Varhead=document.getelementsbytagname (' head '). Item (0);
Varstyle=document.createelement (' link ');
style.href= ' Style.css ';
style.rel= ' stylesheet ';
Style.type= ' Text/css ';
Head.appendchild (style);
Here are two functions that are often used.
Copy Code code as follows:
Functionloadjs (file) {
Varscripttag=document.getelementbyid (' Loadscript ');
Varhead=document.getelementsbytagname (' head '). Item (0);
if (scripttag) head.removechild (Scripttag);
Script=document.createelement (' script ');
script.src= ... /js/mi_ "+file+". js ";
script.type= ' Text/javascript ';
script.id= ' Loadscript ';
Head.appendchild (script);
}
Functionloadcss (file) {
Varcsstag=document.getelementbyid (' loadcss ');
Varhead=document.getelementsbytagname (' head '). Item (0);
if (csstag) head.removechild (Csstag);
css=document.createelement (' link ');
css.href= ... /css/mi_ "+file+". css ";
css.rel= ' stylesheet ';
css.type= ' text/css ';
css.id= ' loadcss ';
Head.appendchild (CSS);
}