// 存储到localstorage 半小时
function setlocalStorage(year,range,data){
    var date = new Date().getTime()
    var key = 'data' + year + range
    var storage = window.localStorage;
 
    var obj = {key:data,'time':date}
    localStorage.setItem(key, JSON.stringify(obj))
}
// 判断是否过期半小时 
function judgelocalStorage(year,range){
    var date = new Date().getTime()
    var key = 'data' + year + range
    var storage = window.localStorage;
    if(JSON.parse(localStorage.getItem(key))){
        if(date - JSON.parse(localStorage.getItem(key)).time > 1800000){
            storage.removeItem(key)
            return null
        } else {
            return JSON.parse(storage.getItem(key)).key
        }
    } else {
        return null
    }

  

posted on 2021-07-18 12:33  白不了的黑发  阅读(332)  评论(0编辑  收藏  举报