[JavaScript] JavaScript实现客户端存储数据 →→→→→进入此内容的聊天室

来自 , 2021-01-12, 写在 JavaScript, 查看 107 次.
URL http://www.code666.cn/view/0b6a27e2
  1.  
  2. db = function() {
  3.     var store = window.localStorage, doc = document.documentElement;
  4.     if (!store) {
  5.         doc.style.behavior = 'url(#default#userData)';
  6.     }
  7.     return {
  8.         /**
  9.          * 保存数据
  10.          */
  11.         set : function(key, val, context) {
  12.             if (store) {
  13.                 return store.setItem(key, val, context);
  14.             } else {
  15.                 doc.setAttribute(key, value);
  16.                 return doc.save(context || 'default');
  17.             }
  18.         },
  19.         /**
  20.          * 读取数据
  21.          */
  22.         get : function(key, context) {
  23.             if (store) {
  24.                 return store.getItem(key, context);
  25.             } else {
  26.                 doc.load(context || 'default');
  27.                 return doc.getAttribute(key) || '';
  28.             }
  29.         },
  30.         /**
  31.          * 删除数据
  32.          * @param {Object}
  33.          * @param {Object}
  34.          */
  35.         rm : function(key, context) {
  36.             if (store) {
  37.                 return store.removeItem(key, context);
  38.             } else {
  39.                 context = context || 'default';
  40.                 doc.load(context);
  41.                 doc.removeAttribute(key);
  42.                 return doc.save(context);
  43.             }
  44.         },
  45.         /**
  46.          * 清空数据
  47.          */
  48.         clear : function() {
  49.             if (store) {
  50.                 return store.clear();
  51.             } else {
  52.                 doc.expires = -1;
  53.             }
  54.         }
  55.     };
  56. }();
  57.  
  58.  
  59.  
  60. //javascript/5075

回复 "JavaScript实现客户端存储数据"

这儿你可以回复上面这条便签

captcha