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元