赞
踩
function setStorage(key,value){
let time = Date.now()
localStorage.setItem(key,JSON.stringify({val:value,time:time}));
}
function getStorage(key){
let val = localStorage.getItem(key)
if(!val) return;
let data = JSON.parse(val)
if(Date.now() - data.time > 7*24*60*60*1000){ // 过期
localStorage.removeItem(key)
}else{
return data.val
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。