标签:
Code:
功能:自定义storge
1 function setStorage(key, val, exp){ //save storage min 2 3 var expires = exp !=‘‘&&typeof(exp) !=‘undefined‘ ? exp*60*1000 + new Date().getTime(): 0; 4 5 localStorage.setItem(key, JSON.stringify({data:val, expires:expires})); 6 7 } 8 9 function getStorage(key){ 10 11 var data = localStorage.getItem(key); 12 13 var dataObj = JSON.parse(data); 14 15 if(new Date().getTime() >= dataObj.expires){ 16 17 console.log(‘expires‘); 18 19 } 20 21 else{ 22 23 return dataObj.data; 24 25 } 26 27 }
标签:
原文地址:http://www.cnblogs.com/vanliga/p/4913916.html