本地存储 APIs store

store.js 是一个实现了浏览器的本地存储的 JavaScript 封装 API,不是通过 Cookie 和 Flash 技术实现,而是使用 localStorage。小弟我主要是用于chrome,Safari,手机Web等先进浏览器里面跑。so....大家可以做兼容哦....

Github地址

本地存储APIs

jsstore(key, data);                 //单个存储字符串数据
store({key: data, key2: data2});  //批量存储多个字符串数据
store(key);                       //获取key的字符串数据
store();                          //获取所有key/data
store(false);                     //清空所有key/data

store.set(key, data[, overwrite]);//=== store(key, data);
store.setAll(data[, overwrite]);  //=== store({key: data, key2: data});
store.get(key[, alt]);            //=== store(key);
store.getAll();                   //=== store();
store.clear();                    //=== store(false);
store.keys();                     //返回所有key的数组
store.forEach(callback);          //循环遍历,返回false结束遍历

store.has(key);         //?判断是否存在返回true/false          
store.remove(key);      //?删除key包括key的字符串数据   

set

单个存储或删除字符串数据
store.set(key, data[, overwrite]);
效果相同store(key, data);

jsstore.set("wcj","1")   //?  1
store.set("wcj")       //?  删除wcj及字符串数据

setAll

批量存储多个字符串数据
store.setAll(data[, overwrite])
效果相同store({key: data, key2: data});

jsstore.setAll({
    "wcj1":123,
    "wcj2":345
}) //存储两条字符串数据

store.setAll(["w1","w2","w3"]) 
//存储三条字符串数据 
//  0? "w1"
//  1? "w2"
//  2? "w3"

get

获取key的字符串数据
store.get(key[, alt])
效果相同store(key)

jsstore.get("wcj1") //获取wcj1的字符串数据
store("wcj1") //功能同上

getAll

获取所有key/data
store.getAll()
效果相同store()

jsstore.getAll() //?JSON
store() //功能同上

clear

清空所有key/data
store.clear()
效果相同store(false)

jsstore.clear() //
store(false)  //功能同上

keys

返回所有key的数组
store.clear()

jsstore.keys() //?["w1", "w2", "w3"]

has

判断是否存在返回true/false
store.has(key)

jsstore.has("w1"); //?true

remove

删除key包括key的字符串数据
store.remove(key)

jsstore.has("w1"); //删除w1

store.set("w1") //这样也是 删除w1

forEach

循环遍历,返回false结束遍历

jsstore.forEach(function(k,d){
    console.log(k,d)
    if (k== 3) return false
})
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值