你的位置:首页 > 软件开发 > 网页设计 > localstorage和sessionstorage上手使用记录

localstorage和sessionstorage上手使用记录

发布时间:2017-05-24 00:00:11
通过阅读各路大神对web存储locastorage和sessionstorage的用法解析,自己试用了一下,在此留个备忘。在项目中,如果用到很多次storage,要存储很多数据,就要把它封装成函数了:(该函数系不知名大神所写,如有侵犯原创,请联系我……)function setS ...

localstorage和sessionstorage上手使用记录

通过阅读各路大神对web存储locastorage和sessionstorage的用法解析,自己试用了一下,在此留个备忘。

在项目中,如果用到很多次storage,要存储很多数据,就要把它封装成函数了:

(该函数系不知名大神所写,如有侵犯原创,请联系我……)

function setStorage(key,value){    if(!window.localStorage){      alert("浏览器不支持localstorage");      return false;    }else{      var storage=window.localStorage;      //写入字段      storage.setItem(key,value);    }  }  function getStorage(key){    if(!window.localStorage){      alert("浏览器不支持localstorage");    }else{      var storage=window.localStorage;      var key=storage.getItem(key);//      console.log(key);      return key;    }}

原标题:localstorage和sessionstorage上手使用记录

关键词:session

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录