Javascript 如何保存切换按钮';s";“开/关”;网站的页面刷新模式?
我正在尝试使用用于我的网站暗/光模式切换的 这是我在其中添加的切换开关,但发生的事情是,当页面刷新时,该开关无法保存其“开/关”模式 当我刷新页面时,它会恢复到默认的“关闭”模式 如何在页面刷新时保存其位置? 也请分享代码Javascript 如何保存切换按钮';s";“开/关”;网站的页面刷新模式?,javascript,html,css,web,Javascript,Html,Css,Web,我正在尝试使用用于我的网站暗/光模式切换的 这是我在其中添加的切换开关,但发生的事情是,当页面刷新时,该开关无法保存其“开/关”模式 当我刷新页面时,它会恢复到默认的“关闭”模式 如何在页面刷新时保存其位置? 也请分享代码 感谢您,您可以存储切换状态(打开或关闭到localstorage)并从localstorage获取值。您可以存储切换状态(打开或关闭到localstorage)并从localstorage获取值。首先更新以下代码“//on page load se the theme.” 改
感谢您,您可以存储切换状态(打开或关闭到localstorage)并从localstorage获取值。您可以存储切换状态(打开或关闭到localstorage)并从localstorage获取值。首先更新以下代码“//on page load se the theme.” 改变
<input type="checkbox" onclick="themeToggle()">
to
<input type="checkbox" onclick="themeToggle()" id="theme-switcher">
到
在“/”页面上首次更新下面的代码加载主题。”部分
改变
<input type="checkbox" onclick="themeToggle()">
to
<input type="checkbox" onclick="themeToggle()" id="theme-switcher">
到
try localStorage您能否共享将在我的案例中使用的“localStorage”代码?try localStorage您能否共享将在我的案例中使用的“localStorage”代码?您能否共享将在我的案例中使用的“localStorage”代码@Ashish你能分享我的案例中使用的“localStorage”代码吗@AshishThank@Libin Prasanth我会更改它。我想你从代码中删除了themeToggle()函数,让我们保留该函数。你能分享完整的脚本吗?谢谢@Libin Prasanth我会更改它。我想你从代码中删除了themeToggle()函数,让我们保持这个功能,你能分享完整的脚本吗?