开发者

HTML5 localStorage replace data to already existing key

开发者 https://www.devze.com 2023-01-16 16:26 出处:网络
I have the following localStorage key: localStorage.setItem(1, \"<div id=\'MyId\'>value 1</div><div id=\'NewId\'>other value</div>\");

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 d开发者_如何转开发elete this key and create a new one, just replace a part of it. Thank you.


Taken 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().

0

精彩评论

暂无评论...
验证码 换一张
取 消