HTML5客户端存储中如何获取key的值?
我使用这样的键存储了一个值 localStorage[title] = text;
我知道我可以通过执行 var text = localStorage[title]< 来调用
text
/code> 但如何获取 title
的值插入到 localStorage
中,以便程序知道要获取什么值。有没有办法循环遍历 localStorage 中的键?
I stored a value with a key like this localStorage[title] = text;
I know I can recall the text
by doing var text = localStorage[title]
but how do you get the value of the title
to insert into the localStorage
so that the program knows what value to get. Is there any way to loop through the keys in the localStorage
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
[删除了
for-in
示例]localStorage
API 允许您迭代键,我们有一个length
属性,以及key
函数。key
函数采用索引并返回键的名称:请在 此处尝试此示例。
[removed
for-in
example]The
localStorage
API, allows you to iterate over the keys, we have alength
property, and thekey
function.The
key
function takes an index and returns the name of the key:Try this example here.