setLocal = function (key, val) { var prefix = "project_list_"; key = prefix + key; var expires = 600; val = JSON.stringify({'val': val, 'expires': new Date().getTime() + expires * 1000}); localStorage.setItem(key, val); }; getLocal = function (key) { var prefix = "project_list_"; key = prefix + key; var val = localStorage.getItem(key); if (!val) { return null; } val = JSON.parse(val); if (val.expires < new Date().getTime()) { localStorage.removeItem(key); return null; } return val.val; };
标签:val,过期,expires,Js,prefix,LocalStorage,key,var,localStorage From: https://www.cnblogs.com/sun-10387834/p/17998741