Home  >  Article  >  Web Front-end  >  Use javaScript to dynamically load Js files and Css files_javascript tips

Use javaScript to dynamically load Js files and Css files_javascript tips

WBOY
WBOYOriginal
2016-05-16 15:35:191246browse

JS dynamic loading of CSS is of great significance in the theme-changeable interface. Users can choose their favorite page display method according to their browsing habits, as explained in detail below.

I hope the following method will be helpful to you.
(1) Use JavaScript to dynamically load Js files

/*JavaScript动态加载Js文件*/ 
var scriptNode = document.createElement('script'); 
scriptNode.src = 'proxy.js?t='+new Date().getTime();/*附带时间参数,防止缓存*/ 
document.head.appendChild(scriptNode); 

(2) Use JavaScript to dynamically load css files

/*JavaScript动态加载Css文件*/ 
var cssNode = document.createElement('link'); 
cssNode.rel = 'stylesheet'; 
cssNode.type = 'text/css'; 
cssNode.media = 'screen'; 
cssNode.href = 'style.css?t='+new Date().getTime();/*附带时间参数,防止缓存*/ 
document.head.appendChild(cssNode); 

The above is how to use javaScript to dynamically load Js files and Css files. I hope it will be helpful to everyone's learning.

Statement:
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