使用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;