1
我有以下選擇:更改所選的選項
<select id="sitestyle" name="stil">
<option value="blue">Blå</option>
<option value="green">Grön</option>
<option value="red">Röd</option>
<option value="pink">Rosa</option>
</select>
我節省了值的用戶已選擇localStorage
。假設用戶選擇value="pink"
,然後將其保存到localStorage
,用戶關閉瀏覽器並再次打開我想要value="pink"
自動選擇。目前,無論localStorage
中保存了什麼,始終爲value="blue"
。
不能使用jQuery/Ajax,但JavaScript是好的。
編輯
我有以下JS:
function setStyleFromStorage(){
style = localStorage.getItem("style");
document.getElementById('css_style').setAttribute('href', style);
if(style == "blue"){
document.getElementById("sitestyle").selectedIndex() = 0;
}else if(style == "green"){
document.getElementById("sitestyle").selectedIndex() = 1;
}else if(style == "red"){
document.getElementById("sitestyle").selectedIndex() = 2;
}else if(style == "pink"){
document.getElementById("sitestyle").selectedIndex() = 3;
}
}
到目前爲止,你做了什麼?js代碼,小提琴? –
添加我的JS代碼。 – user3310428
可能有助於瞭解:http://stackoverflow.com/questions/9948284/how-persistent-is-localstorage – Cypher