![](/img/trans.png)
[英]Why local storage is not working even it should not open after page refresh?
[英]bringing local storage page to page not working
我有一個select元素可以更改我的網站的主題。 在其中,我使用本地存儲來更改每個頁面上的主題,即使更改器僅位於主頁上也是如此。 它設置了本地存儲密鑰,但是我無法在其他頁面上找到它。 不過,它可以在主頁上運行。 我檢索本地存儲的代碼是
function setTheme() {
theme = window.localStorage.getItem('theme');
document.getElementById('themepicker').setAttribute('href', theme);
document.getElementById(theme).setAttribute('selected', 'selected');
}
更改它的代碼是
function changeTheme(theme) {
sltr = document.getElementById('themepicker');
theme = theme + '.css';
sltr.setAttribute('href', theme);
window.localStorage.setItem('theme', theme);
}
該函數在頁面加載時運行。
問題是您只是將theme
重置為theme
而是將主題更改為新主題,而theme
從未定義或設置為新theme
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.