静态页面实现换肤功能(无cookie)
程序员文章站
2022-03-08 14:48:39
...
//1、将已存在的样式表css禁用掉
for ( i = 0; i < document.styleSheets.length; i++ )
{
document.styleSheets[i].disabled = true;
}
//2、添加新的样式表
var selectedTheme = ...;//目标样式的路径
var head = document.getElementsByTagName('HEAD').item(0);
var ga = document.createElement('link');
ga.rel = "stylesheet";
ga.type = 'text/css';
ga.href = selectedTheme ;
head.appendChild(ga);