浏览器本地缓存localStorage
web 本地存储
var storage={ save2Local:function (key,val) { localStorage.setItem(key,val); }, restore4Local:function(key) { if (window.localStorage) { return localStorage.getItem(key); } }, /*** * 清除localStorage */ removeLocalStorage:function (key) { if(key){ localStorage.removeItem(key); } } };
应用:
var currentDateTime=new Date(); var date_format='%Y%m%d'; var currentDate=currentDateTime.format2(date_format);//20170316 console.log('currentDate:'+currentDate); //缓存到浏览器 var browserCache=function (prefix) { var answer=$('textarea[name=content]').val(); if(answer){//每次currentDate 都需要重新生成 currentDate=new Date().format2(date_format);//20170316 storage.save2Local(prefix+currentDate,answer); } }; //从浏览器中获取缓存 var getbrowserCache=function (prefix) { var answer=storage.restore4Local(prefix+currentDate); if(!answer){ currentDateTime.setDate(currentDateTime.getDate() - 1); currentDate=currentDateTime.format2(date_format);//20170316 answer=storage.restore4Local(prefix+currentDate); } answer&&$('textarea[name=content]').val(answer).focus(); }
相关推荐
拭血 2020-06-02
wetyu 2020-08-02
PkJY 2020-06-17
KungLun 2020-02-03
H女王范儿 2020-04-22
芯果科技蔡彦 2020-04-14
H女王范儿 2019-11-18
baynkbtg 2019-10-31
zjnig的信息仓库 2014-11-10
csdnInfo 2015-02-25
OldSoldier 2012-01-04
88264154 2015-12-27
大数据实战派 2015-12-31
MrSunOcean 2019-09-08
phillip 2019-04-15
xiluoenm 2013-05-16
LeavesYu 2019-07-01
caiselangren 2019-07-01