2011-10-08 101 views
0

我想重置该用户输入的值的本地存储格式a的值。更新本地存储值

我把默认值

//default setting values 
localStorage.autoalert="false"; 

但是当用户提交表单此代码excuting

var activateAutoAlert=$("input[name='activateAutoAlert']").is(":checked")?"true":"false"; 
alert(activateAutoAlert); 
localStorage.autoalert=String(activateAutoAlert); 

警报的作品,并显示“真”值,但本地存储还是“假” !

如何将变量值设置为本地存储。 我试过这些方法

localStorage.autoalert=activateAutoAlert; 
localStorage.autoalert=activateAutoAlert.toString(); 

没有人更新本地存储的值。有什么建议么??

回答

0

This工作对我罚款:

localStorage.autoalert = "false"; 
window.alert(localStorage.getItem("autoalert")); 
$("input[name='activateAutoAlert']").click(function() { 
    var activateAutoAlert = $("input[name='activateAutoAlert']").is(":checked") ? "true" : "false"; 
    localStorage.autoalert = activateAutoAlert; 
    alert(localStorage.autoalert); 
}); 

的形式提交重新加载相同的页面?你如何确保你的代码在重装后没有执行autoalertfalse

+0

相同的代码今晚工作,似乎需要关闭chrome再次打开,以使本地存储更新过程。 – palAlaa