我正在寻找一种方式来加载页面时热插拔样式表。这是我目前的解决方案,它的工作原理,但它有一些限制/问题。优雅的方式交换主题样式表,无需重新加载页面
HTML头:
<link id="theme" href="themes/theme1.css" rel="stylesheet" type="text/css">
JS:
themes = [
"themes/theme1.css",
"themes/theme2.css"
];
function themeSwitch() {
var currentTheme = $("#theme").attr('href');
var themeID = themes.indexOf(currentTheme);
themeID = (themeID + 1) % themes.length;
$("#theme").attr('href', themes[themeID]);
}
的浏览器需要进行额外的GET请求我的这种方法的问题是,当函数被调用的变化不是瞬间为css文件。另一个问题是,如果用户在使用该页面时暂时断开连接,他们将被留下而没有主题。
可能的重复[如何使用jQuery切换我的CSS样式表?](http://stackoverflow.com/questions/7846980/how-do-i-switch-my-css-stylesheet-using-jquery) – Qhuea
@Qhuea该问题的解决方案每次切换主题时都需要GET请求。 – luctowers