首页 > 其他 > 详细

userData 本地存储

时间:2014-08-21 18:53:04      阅读:318      评论:0      收藏:0      [点我收藏+]

 

(function(window, undefined){

  function userData(){
    var doc = document;
    var name = location.host || ‘localhost‘;
    var store = doc.createElement(‘div‘);
    var expires = new Date();
    var keys = [];

    store.style.display = ‘none‘;
    store.style.behavior = ‘url("#default#userData")‘;
    doc.body.appendChild(store);

    expires.setDate(expires.getDate()+365);
    store.expires = expires.toUTCString();

    store.load(name);

    function getItem(key){
      return store.getAttribute(key);
    }

    function setItem(key, val){
      store.setAttribute(key, val);
      store.save(name);
      return this;
    }

    function removeItem(key){
      store.removeAttribute(key);
      store.save(name);
      return this;
    }

    return {
      length: length,
      getItem: getItem,
      setItem: setItem,
      removeItem: removeItem
    }
  }

  function winLocalStorage(store){

    function getItem(key){
      return store.getItem(key);
    }

    function setItem(key,val){
      store.setItem(key, val);
      return store;
    }

    function removeItem(key){
      store.removeItem(key);
      return store;
    }

    return {
      getItem: getItem,
      setItem: setItem,
      removeItem: removeItem
    }
  }
  
  window.LocalStorage = window.localStorage && (new winLocalStorage(window.localStorage)) || new userData();

})(window)

alert(LocalStorage.setItem(‘aa‘, 123).getItem(‘aa‘));

 

userData 本地存储,布布扣,bubuko.com

userData 本地存储

原文:http://www.cnblogs.com/bjmumu/p/3582118.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!