从localstorage javascript中删除价值 [英] remove value from localstorage javascript

查看:115
本文介绍了从localstorage javascript中删除价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Javasscript中的 localStorage 中删除项目,但是它不起作用.

I'm trying to remove item from localStorage in javasscript but it doesn't work.

它只能手动处理以下事件的顺序

It only works manually for the sequence of the following events

Right click --> Inspect element --> Resources --> localStorage --> Right click --> Delete 

我尝试过:

localStorage.clear(); 

localStorage.removeItem(key); // the key is the link of the page and 
                              // the value is the selected word in the page 

都无法正常工作,我可以使用localStorage.setItem(key, vaule)保存项目,并使用localStorage.getItem(key)从localStorage获取项目,但是我无法删除它们.

and both didn't work, I can save item using localStorage.setItem(key, vaule) and get items from localStorage using localStorage.getItem(key) but I can't remove them.

推荐答案

您要寻找的是什么

deleter void removeItem(DOMString key);

您可以这样实现:

localStorage.removeItem(key)

关于本地存储的所有信息都可以在此处的W3 html5网上规范中找到存储.

Everything about local storage can be found here on the W3 html5 spec for web storage.

随着更多解释,您可能会发现此文档更有用.

You may find this document more helpful as it goes into more explanation.

*本地存储不是最终规格,并且可能会更改.

*Local storage is not a finished spec and these could change.

这篇关于从localstorage javascript中删除价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆