Home > Web Front-end > JS Tutorial > body text

Use javaScript to dynamically load Js files and Css files_javascript tips

WBOY
Release: 2016-05-16 15:35:19
Original
1213 people have browsed it

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); 
Copy after login

(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); 
Copy after login

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.

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!