从localstorage javascript中删除值

我试图在
javasscript中从localStorage中删除项目,但它不起作用.

它仅适用于以下事件的序列

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获取项目,但我无法删除它们.

最佳答案 你要找的是这个:

deleter void removeItem(DOMString key);

您可以这样实现:

localStorage.removeItem(key)

关于本地存储的一切都可以找到here on the W3 html5 spec for web storage.

你可能会发现这个document more helpful as it goes into more explanation.

*本地存储不是完成的规范,这些可能会改变.

点赞