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

使用javaScript动态加载Js文件和Css文件_javascript技巧

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

JS动态加载CSS 在可换主题的界面中具有很重要的意义,用户可以根据自己的浏览习惯选择自己喜欢的页面显示方式,下面详细说明。

希望下面的方法对你有帮助。
(1)使用JavaScript动态加载Js文件

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

(2)使用JavaScript动态加载css文件

/*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

以上就是使用javaScript动态加载Js文件和Css文件的方法,希望对大家的学习有所帮助。

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!