zoukankan      html  css  js  c++  java
  • userData 本地存储

    (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'));
  • 相关阅读:
    【图论】第k短路
    【图论】差分约束系统
    【图论】最短路
    【图论】Johnson算法
    HDU5878
    HDU5900
    pow的小事不简单
    math汇总
    Bellman-Ford最短路径
    图的遍历
  • 原文地址:https://www.cnblogs.com/bjmumu/p/3582118.html
Copyright © 2011-2022 走看看