Javascript 如何使用localStorage保持禁用输入(即使已刷新)

Javascript 如何使用localStorage保持禁用输入(即使已刷新),javascript,jquery,html,local-storage,Javascript,Jquery,Html,Local Storage,我想做的是,如果我单击单选按钮上的“否”,它将禁用,即使我刷新或关闭浏览器并再次打开它,它仍将禁用,直到我单击“是”按钮,禁用将消失 如何使用localStorage实现这一点 测试链接: html: 尝试以下代码,检查演示,更改单选按钮并在文本框中输入一些文本,然后再次运行JSFIDLE,它将保持相同的状态 如果没有按钮,我需要禁用它clicked@user3763580代码更新的pl检查你从哪里得到这个itmEmployee和itmTest?@user3763580它是HTML5中存储的一个

我想做的是,如果我单击单选按钮上的“否”,它将禁用,即使我刷新或关闭浏览器并再次打开它,它仍将禁用,直到我单击“是”按钮,禁用将消失

如何使用localStorage实现这一点

测试链接:

html:


尝试以下代码,检查演示,更改单选按钮并在文本框中输入一些文本,然后再次运行JSFIDLE,它将保持相同的状态


如果没有按钮,我需要禁用它clicked@user3763580代码更新的pl检查你从哪里得到这个itmEmployee和itmTest?@user3763580它是HTML5中存储的一个密钥localStorage@CDspace它没有我想要的答案。
<input type="radio" name="employed" id="employed_v1" value="Yes" required="required" /> Yes<br />
<input type="radio" name="employed" id="employed_v0" value="No" required="required" /> No <br>

<input type="text" name="test" id="test" />
$(document).ready(function () {

    $('#test').on("keyup change", function () {
       debugger;
        localStorage.setItem($(this).attr("id"), $(this).val())
    });


    $('#test').each(function (ind, val) {
            debugger;

         $(val).val(localStorage.getItem($(val).attr("id")))

    });

    $('#employed_v1, #employed_v0').on("change", function () {
        localStorage.setItem('employed', $(this).attr("id"))
    });

    $('#' + localStorage.getItem('employed')).attr('checked', true);

$('[id="employed_v0"]').on('click', function(){
        $('#test').val('');
        localStorage.removeItem('test');
        $('#test').prop('disabled', true);        
     });
$('[id="employed_v1"]').on('click', function(){
        $('#test').prop('disabled', false);
     });

});
$(document).ready(function(){
    if(localStorage.getItem("itmEmployee") == "Yes")
        $("#employed_v1").prop("checked", true);
    else
        $("#employed_v0").prop("checked", true);

    if(localStorage.getItem("itmEmployee") == "Yes")
        $("#test").prop("disabled", false);
    else
        $("#test").prop("disabled", true);

    $("#test").val(localStorage.getItem("itmTest"));

    $("[name=employed]").on("change", function(){
        localStorage.setItem("itmEmployee", $(this).val());

        if($(this).val() == "Yes")
            $("#test").prop("disabled", false);
        else
            $("#test").prop("disabled", true);
    });

    $("#test").on("change", function(){
        localStorage.setItem("itmTest", $(this).val());
    });
});