我有一个HTML网站,它运行在两台不同的PC上,其中有一些来自metro.css
的切换开关。我试图通过localStorage
方法使用onclick
保存其状态。
<label class="switch">
<input type="checkbox" id="switch_104_02" checked="checked" onClick="switcherFunction(this.id)">
<span class="check"/>
</label>
这是JS函数:
function switcherFunction(switcher_id) {
if (switcher_id.checked == true) {
localStorage.setItem(switcher_id, false);
localStorage.getItem(switcher_id);
} else {
localStorage.setItem(switcher_id, true);
localStorage.getItem(switcher_id);
}
}
答案 0 :(得分:0)
请尝试
<input type="checkbox" id="switch_104_02" checked="checked" onClick="switcherFunction()">
function switcherFunction(){
if($('#switch_104_02').is(':checked') == true){
localStorage.setItem("switch_104_02", "false");
localStorage.getItem("switch_104_02");
}else{
localStorage.setItem("switch_104_02", "true");
localStorage.getItem("switch_104_02");
}
}