LocalStorageUtils
对localStorage进行封装:
var LocalStorageUtils = new function (){
if(window.localStorage==null){
throw new Error('当前浏览器不支持本地存储!');
};
var _storage = window.localStorage;
/**
* 设置(添加,修改)本地存储项
* @param {*} key
* @param {*} value
*/
this.set=function(key,value){
//storage[key]=value;
_storage.setItem(key,value);
},
/**
* 获取本地存储项
* @param {*} key
*/
this.get=function(key){
//return storage[key];
return _storage.getItem(key);
},
/**
* 移除本地存储项
* @param {*} key
*/
this.remove=function(key){
//delete storage[key];
_storage.removeItem(key);
},
/**
* 清空本地存储项
*/
this.clear= function(){
_storage.clear();
},
/**
* 获取本地存储项所有的key
*/
this.keys=function(){
var allKeys = [];
for(var i=0;i<_storage.length;i++){
allKeys.push(_storage.key(i));
}
return allKeys;
},
/**
* 获取本地存储项条数
*/
this.length = function(){
return _storage.length;
},
/**
* 设置(添加,修改)本地JSONObj存储项
* @param {*} key
* @param {*} value
*/
this.setJSONObj=function(key,value){
this.set(key,JSON.stringify(value));
},
/**
* 获取本地JSONObj存储项
* @param {*} key
*/
this.getJSONObj= function(key){
return JSON.parse(this.get(key));
}
}();
LocalStorageUtils的更多相关文章
随机推荐
- tensorflow 笔记 16:tf.pad
函数: tf.compat.v1.pad tf.pad 函数表达式如下: tf.pad( tensor, paddings, mode='CONSTANT', name=Non ...
- golang教材
https://golangbot.com/buffered-channels-worker-pools/ https://golang.org/doc/ https://medium.com/go- ...
- Go 汇编入门
https://golang.org/doc/asm https://github.com/teh-cmc/go-internals/tree/master/chapter1_assembly_pri ...
- layui 复选框checkbox 实现全选全选
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Qt组件(例如按钮、树形控件)上响应鼠标右键
ui->textEdit->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->textEdit,SIGNAL(cust ...
- sql server数据库显示“单用户”的解决方法
USE master; GO DECLARE @SQL VARCHAR(MAX); SET @SQL='' SELECT @SQL=@SQL+'; KILL '+RTRIM(SPID) --杀掉该进程 ...
- PageRank算法原理与Python实现
一.什么是pagerank PageRank的Page可是认为是网页,表示网页排名,也可以认为是Larry Page(google 产品经理),因为他是这个算法的发明者之一,还是google CEO( ...
- allure与junit结合生成漂亮的demo
1.allure安装 环境配置可参考https://blog.csdn.net/huggh/article/details/90905845,且博客中也分享了官网的案例https://github.c ...
- python 科学计算基础库安装
1.numpyNumPy(Numeric Python)是用Python进行科学计算的基本软件包. NumPy是Python编程语言的扩展,增加了对大型多维数组和矩阵的支持,以及一个大型的高级数学函数 ...
- 使用全备+binlog日志恢复数据库
1.binlog日志类型 Statement 只记录执行的sql语句,磁盘占用少,但是恢复的时候容易出问题.InodeDB不能使用Statement . Row 记录修改后的具体数据,磁盘占用较多 M ...