javascript原生Html5本地存储之jsStorage.js
程序员文章站
2024-01-21 22:06:34
...
jsStorage.js实现对html5的localstorage和sessionStorage的封装操作;
详情请阅读: https://git.oschina.net/wuquanyao/JsStorage
详情请阅读: https://git.oschina.net/wuquanyao/JsStorage
/*+==============================================
+ 我不只是一个程序员,我更希望用此创造价值
+ author:wuquanyao
+ email:wqynqa@163.com
* version:1.0.0
+==============================================*/
var storage=(function(){
var Storage = function(type){
this.storage = null;
if(typeof('type') === 'undefined' || type === 'local')
this.storage = window.localStorage;
else if(type === 'session')
this.storage = window.sessionStorage;
}
Storage.prototype.set=function(key, value){
this.storage.setItem(key, escape(value));
}
Storage.prototype.get=function(key){
return unescape(this.storage.getItem(key));
}
Storage.prototype.remove=function(key){
this.storage.removeItem(key);
}
Storage.prototype.clear=function(){
this.storage.clear();
}
Storage.prototype.key=function(index){
return this.storage.key(index);
}
Storage.prototype.hasKey=function(key)
{
for(var i in this.storage){
if(i === key){
return true;
}
}
return false;
}
Storage.prototype.hasVal=function(value)
{
for(var i in this.storage){
if(unescape(this.storage[i]) === value){
return true;
}
}
return false;
}
Storage.stringify = function(data){
return JSON.stringify(data);
}
Storage.parse = function(data){
return JSON.parse(data);
}
Storage.support = function(){
if(window.localStorage && window.sessionStorage) return true;
return false;
}
return Storage;
})(window);
AD:真正免费,域名+虚机+企业邮箱=0元
上一篇: 微信api 图文消息案例
推荐阅读
-
javascript原生Html5本地存储之jsStorage.js
-
HTML5本地存储之Web Storage篇
-
HTML5本地存储之Database Storage应用介绍
-
HTML5本地存储之Web Storage应用介绍
-
突袭HTML5之Javascript API扩展3—本地存储全新体验
-
HTML5 本地存储之如果没有数据库究竟会怎样
-
html5本地存储之localstorage 、本地数据库、sessionStorage简单使用示例
-
HTML5本地存储之Web Storage详解
-
HTML5本地存储之Database Storage应用介绍
-
HTML5本地存储之Web Storage应用介绍