美文网首页
6.sessionstorage存储

6.sessionstorage存储

作者: Radius_ | 来源:发表于2018-11-07 16:23 被阅读0次

1.存储字符串:

    var  setMobile =  iphoneXR;

存:

    sessionstorage.setItem('mobile',setMobile);

取:

    var  getMobile =sessionstorage.getItem('mobile');

    console.log(getMobile)        //iphoneXR

2.存储对象:

    var userEntity = {

        name: 'tom',

        age: 22

    };

存:

    var obj=JSON.stringify(userEntity);     //将对象转为文本

    sessionstorage.setItem('obj',obj);         

取:

    var  getObj=sessionstorage.getItem('obj');

    var getObj2=JSON.parse(getObj);         //将文本转为对象

相关文章

网友评论

      本文标题:6.sessionstorage存储

      本文链接:https://www.haomeiwen.com/subject/ccpvxqtx.html