admin管理员组文章数量:1168587
I have the following localStorage key:
localStorage.setItem(1, "<div id='MyId'>value 1</div><div id='NewId'>other value</div>");
Is it possible to replace, change only the second id, make the:
<div id='MyId'>value 1</div><div id='NewId'>other value</div>
turn into
<div id='MyId'>value 1</div><div id='NewId'>replaced value</div>
I do not want to delete this key and create a new one, just replace a part of it. Thank you.
I have the following localStorage key:
localStorage.setItem(1, "<div id='MyId'>value 1</div><div id='NewId'>other value</div>");
Is it possible to replace, change only the second id, make the:
<div id='MyId'>value 1</div><div id='NewId'>other value</div>
turn into
<div id='MyId'>value 1</div><div id='NewId'>replaced value</div>
I do not want to delete this key and create a new one, just replace a part of it. Thank you.
Share Improve this question edited Sep 20, 2010 at 11:12 Alex Gyoshev 12k4 gold badges47 silver badges76 bronze badges asked Sep 20, 2010 at 11:03 MirceaMircea 11.6k26 gold badges65 silver badges98 bronze badges1 Answer
Reset to default 45Taken from Dive into HTML5:
Calling setItem() with a named key that already exists will silently overwrite the previous value.
So read the value with getItem() [if needed], do your replace, set the new value with setItem().
本文标签: javascriptHTML5 localStorage replace data to already existing keyStack Overflow
版权声明:本文标题:javascript - HTML5 localStorage replace data to already existing key - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1737607147a1998577.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论