首页 > 代码库 > userData 本地存储
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‘));
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。