javascript - HTML5 本地存储和 jQuery : Delete localstorage keys starting with a certain word

标签 javascript jquery html local-storage

我有 2 个应用程序与 localstorage 一起工作,我想知道如何删除所有以 note- 和 todo- 开头的键。我知道 localstorage.clear() 会清除所有内容,但这不是我的目标。

这是我本地存储中的一个示例:enter image description here

我想使用 jquery 单击按钮删除所有 todo-*,并使用 jquery 单击其他按钮删除所有 note-*。

非常感谢

最佳答案

Object.keys(localStorage)
      .forEach(function(key){
           if (/^todo-|^note-/.test(key)) {
               localStorage.removeItem(key);
           }
       });

关于javascript - HTML5 本地存储和 jQuery : Delete localstorage keys starting with a certain word,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7591893/

相关文章:

javascript - 计算用户使用 jquery 或 javascript 将元素悬停了多少秒?

Javascript:无法使用 for in 循环获取数组内的值

javascript - contenteditable div 中的 HTML5 可拖动元素 - 在第一次放置后停止工作 - 为什么?

css - html div 的高度 (%)

javascript - 在jsp中刷新页面后检索先前填充的值和选择

javascript - 如何动态添加带有文本框的表格行?

jquery - 仅在桌面上将导航固定到顶部

html - 高度不同时如何获得紧凑的div?

javascript - Webpack & Bower : Multiple css & js files

php - 实时多人游戏技术