<script type="text/javascript">
//封装过期控制代码
function set(key,value){
var curTime = new Date().getTime();
localStorage.setItem(key,JSON.stringify({data:value,time:curTime}));
}
function get(key,exp){
var data = localStorage.getItem(key);
var dataObj = JSON.parse(data);
if (new Date().getTime() - dataObj.time>exp) {
console.log('信息已过期');
//alert("信息已过期")
}else{
var dataObjDatatoJson = JSON.parse(dataObj.data)
return dataObjDatatoJson;
}
}
</script
转载: https://blog.csdn.net/xyphf/article/details/51830770
网友评论