Localstorage getItem和setItem不工作在ie 9

时间:2015-11-03 10:07:35

标签: javascript jquery html5 internet-explorer local-storage

我试过搜索SO在哪里我得到了一些想法如何在ie9中启用setItem和getItem但是没有使用它没有工作在ie 9

function assignValue() {
    var checkedRadioValue = -1;
    if (document.getElementById("ug").checked)
    {
        checkedRadioValue = 1;
    }
    else if(document.getElementById("pg").checked)
    {
        checkedRadioValue = 2;
    }
    else if(document.getElementById("cu").checked)
    {
        checkedRadioValue = 3;
    }
    //localStorage.setItem("CheckedRadioValue", checkedRadioValue);

    localStorage.setItem("CheckedRadioValue", checkedRadioValue);
}

其实我正在为ie9

尝试这样的事情
if(window.localStorage) { 
    localStorage.setItem("CheckedRadioValue", checkedRadioValue);
}

像这样我试图在ie9中使用localstorage获取值,这在chrome,firefox中完美运行

var checkedRadioValue = parseInt(localStorage.getItem("CheckedRadioValue"));
    if (checkedRadioValue != -1) {
        if (checkedRadioValue === 1) {
            $('.local_Field ').each(function() {
                $(this).rules("remove","required");
            });
        }
        else if (checkedRadioValue === 3){
            $('.local_Field').each(function() {
                $(this).rules("remove","required");
            });
            $("#edu_info").hide();
            $(".local_Field").removeClass('required_Field');
            //$('.local_Field ').addClass('chumma');
        }
        else{
            $('.local_Field ').each(function() {
                $(this).rules("add","required");
            });
             $(".local_Field").addClass('required_Field');
        };
        //localStorage.removeItem("CheckedRadioValue");
    }

这就是我在IE10中发现的错误

SCRIPT5007: Unable to get property 'getItem' of undefined or null reference 

提前致谢

0 个答案:

没有答案