【发布时间】:2017-10-22 05:42:13
【问题描述】:
所以我有一个 JS 脚本,当用户按下显示暗模式的按钮时,页面切换到 dark_theme.css(而不是使用轻模式 css 的 theme.css)并且当用户按下轻模式按钮时切换回 theme.css。所以我的问题是,当用户使用 darm_theme.css 并加载不同的页面或刷新当前页面时,主题会切换回浅色模式。如何以某种方式保存用户的选择/选择?
function swapStyleSheet(sheet){
document.getElementById('theme').setAttribute('href', sheet);
}
I have one file called theme.css and one more called dark_theme.css
<link id="theme" rel="stylesheet" type="text/css" href="theme.css">
...more html here...
<p><button class="colormode" onclick="swapStyleSheet('dark_theme.css')">Dark Mode</button> <button class="colormode" onclick="swapStyleSheet('theme.css')">Light Mode</button></p>
【问题讨论】:
标签: javascript html css