Home > Web Front-end > JS Tutorial > Javascript dynamic loading css method summary_javascript skills

Javascript dynamic loading css method summary_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 18:50:10
Original
1066 people have browsed it
1. Used to load necessary files in external CSS files
@importurl(style.css);
//Can only be used in CSS files or style tags
2. Simply load an external CSS file into the page
document.createStyleSheet(cssFile);
2. Use the createElement method to create a CSS Link tag
varhead=document.getElementsByTagName('HEAD ').item(0);
varstyle=document.createElement('link');
style.href='style.css';
style.rel='stylesheet';
style .type='text/css';
head.appendChild(style);
The following are two functions that are often used.
Copy code The code is 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);
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Apakah pengumpulan sampah JavaScript?
From 1970-01-01 08:00:00
0
0
0
Apakah fungsi cangkuk JavaScript?
From 1970-01-01 08:00:00
0
0
0
JavaScript 후크 기능이란 무엇입니까?
From 1970-01-01 08:00:00
0
0
0
Was sind JavaScript-Hook-Funktionen?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template