JS動態加載CSS 在可換主題的界面中具有很重要的意義,用戶可以根據自己的浏覽習慣選擇自己喜歡的頁面顯示方式,下面詳細說明。
希望下面的方法對你有幫助。
(1)使用JavaScript動態加載Js文件
/*JavaScript動態加載Js文件*/
var scriptNode = document.createElement('script');
scriptNode.src = 'proxy.js?t='+new Date().getTime();/*附帶時間參數,防止緩存*/
document.head.appendChild(scriptNode);
(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);
以上就是使用javaScript動態加載Js文件和Css文件的方法,希望對大家的學習有所幫助。