• 技术文章 >php教程 >php手册

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

    2016-06-07 11:36:48原创501
    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元

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    上一篇:【免费下载】EBCORE后台开发框架1.2测试版发布! 下一篇:Gms管理系统v1.1.1

    相关文章推荐

    • 解析如何通过PHP函数获取当前运行的环境 来进行判断执行逻辑(小技巧)• php下几个常用的去空、分组、调试数组函数• swfupload 多文件上传实现代码• 用PHP与XML联手进行网站编程代码实例• 谈谈新手如何学习PHP网络编程第1/2页

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网