var data = {
"mid":"10000XXX",
"css":{
"header":{
"background-color":"#000",
"color":"#fff",
"font-size":"10"
},
"txndescr":{
"background-color":"#000",
"color":"#fff",
"font-size":"10"
}
}
};
我已通过以下方式存储在本地存储中,
// Put the object into storage
localStorage.setItem('defaultTheme', JSON.stringify(data));
我想更新“标题”背景颜色(#000 到 #FFF)属性。如何更新该值。
最佳答案
更新 localStorage 中已有的 Object 的方法如下:
- 获取现有项目
- 更新值
保存更新的项目
//1. Fetch the existing item var data = JSON.parse(localStorage.getItem('defaultTheme')); //2. Update the value data.css.header['background-color'] = '#CCC'; //3. Save the update item localStorage.setItem('defaultTheme', JSON.stringify(data));
干杯
关于javascript - 使用 HTML5 localstorage 更新 json 键的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31783787/