欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

javascript原生Html5本地存储之jsStorage.js

程序员文章站 2024-02-01 13:02:22
...
jsStorage.js实现对html5的localstorage和sessionStorage的封装操作;
详情请阅读: 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元