zoukankan      html  css  js  c++  java
  • H5 本地存储 localstorage封装

    store.js 是一个实现了浏览器的本地存储的 JavaScript 封装 API,不是通过 Cookie 和 Flash 技术实现,而是使用 localStorage、globalStorage 和 userData 行为。

    示例代码:

     1 // 存储 'username' 的值为 'marcus'
     2     store.set('username', '123');
     3 
     4     // 移除 'username' 字段
     5     store.remove('username');
     6 
     7     // 获取 'username'
     8     var aaa = store.get('username');
     9 
    10     // 清除所有本地存储
    11     store.clear();
    12 
    13     // 存储对象 - 自动调用 JSON.stringify
    14     store.set('user', { name: 'marcus', likes: 'javascript' })
    15 
    16     // 获取存储的对象 - 自动执行 JSON.parse
    17     var user = store.get('user')
    18     console.log(user.name + ' likes ' + user.likes)
    19 
    20     // 从所有存储中获取值
    21     store.getAll().user.name == 'marcus'
    22 
    23     // 遍历所有存储
    24     store.forEach(function(key, val) {
    25         console.log(key, '==', val)
    26     })

    GitHub地址:https://github.com/marcuswestin/store.js

  • 相关阅读:
    暴力,DFS,比较字符串
    暴力求解最大乘积
    油田!
    八皇后的问题
    巡逻的机器人
    骑士的移动
    二叉树遍历
    新兵训练(=@__@=)
    打牌~~~
    八皇后
  • 原文地址:https://www.cnblogs.com/kongwei/p/6605400.html
Copyright © 2011-2022 走看看