简体   繁体   English

从localstorage javascript中删除价值

[英]remove value from localstorage javascript

I'm trying to remove item from localStorage in javasscript but it doesn't work. 我正在尝试从javasscript中的localStorage删除项目,但是它不起作用。

It only works manually for the sequence of the following events 它仅适用于以下事件的顺序

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

I tried: 我试过了:

localStorage.clear(); 

and

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

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. 两者都不起作用,我可以使用localStorage.setItem(key, vaule)保存项目localStorage.setItem(key, vaule)并使用localStorage.getItem(key)从localStorage获取项目,但是我无法删除它们。

what your looking for is this: 您在寻找什么?

deleter void removeItem(DOMString key);

You could implement this like so: 您可以这样实现:

localStorage.removeItem(key)

Everything about local storage can be found here on the W3 html5 spec for web storage. 有关本地存储的所有内容都可以在W3 html5规范的Web存储中找到。

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.clear当前可在主要浏览器中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM