使用localStorage保存复选框值 [英] Use localStorage to save a checkbox value
本文介绍了使用localStorage保存复选框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个show/hide div,可以通过复选框状态进行切换,尽管它可以正常工作,但我想让localStorage保存复选框状态,但是我不知道如何实现代码的本地存储部分,放置在哪里.非常感谢您的帮助.
I have a show / hide div which is toggled by a checkbox state, although it works fine I would like to have localStorage save the checkbox state, but I don't know how to implement the local storage part of the code and where to place it. Any help gratefully received.
$(document).ready(function() {
$('#checkbox1').change(function() {
$('#div1').toggle();
});
});
<input type="checkbox" id="checkbox1" value="1" />
<div id="div1">Text to be toggled</div>
推荐答案
尝试以下操作: http://jsfiddle .net/sQuEy/4/
checkboxes[i].checked = localStorage.getItem(checkboxes[i].value) === 'true' ? true:false;
这篇关于使用localStorage保存复选框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文