HTML5本地存储& jQuery:删除以某个单词开头的localstorage键 [英] HTML5 Localstorage & jQuery: Delete localstorage keys starting with a certain word
本文介绍了HTML5本地存储& jQuery:删除以某个单词开头的localstorage键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个应用程序与localstorage一起工作,我想知道如何删除所有以note-和todo-开头的密钥。我知道localstorage.clear()清除了所有内容,但那不是我的目标。
以下是本地存储中的示例:
我想用一个按钮删除所有的todo- *点击和所有的笔记 - *与其他按钮点击使用jquery。
非常感谢
解决方案 (key){
if(/ ^ todo- | ^ note - /。test((key)){
$> $ $ $ $ $ $ $ $ b $ forEach key)){
localStorage.removeItem(key);
}
});
if(/ ^ todo- | ^ note - /。test((key)){
$> $ $ $ $ $ $ $ $ b $ forEach key)){
localStorage.removeItem(key);
}
});
I have 2 apps working together with localstorage and I was wondering how can I delete all the keys which start with note- and todo- . I know localstorage.clear() clears everything but thats not my aim.
Here is an example of what I have in my localstorage:
Where I want to delete all the todo-* with a button click and all note-* with other button click using jquery.
Thanks alot
解决方案
Object.keys(localStorage)
.forEach(function(key){
if (/^todo-|^note-/.test(key)) {
localStorage.removeItem(key);
}
});
这篇关于HTML5本地存储& jQuery:删除以某个单词开头的localstorage键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文