采用setItem()方法存储
sessionStorage.setItem(‘testKey‘,‘这是一个测试的value值‘); // 存入一个值
sessionStorage.getItem(‘testKey‘); // => 返回testKey对应的值
通过属性方式存储
sessionStorage[‘testKey‘] = ‘这是一个测试的value值‘;
sessionStorage[‘testKey‘]; // => 这是一个测试的value值
sessionStorage也可存储Json对象:存储时,通过JSON.stringify()将对象转换为文本格式;读取时,通过JSON.parse()将文本转换回对象var userEntity = { ???name: ‘tom‘, ???age: 22}; // 存储值:将对象转换为Json字符串sessionStorage.setItem(‘user‘, JSON.stringify(userEntity)); // 取值时:把获取到的Json字符串转换回对象var userJsonStr = sessionStorage.getItem(‘user‘);userEntity = JSON.parse(userJsonStr);console.log(userEntity.name); // => tom
原文链接 :http://www.cnblogs.com/polk6/p/5512979.html
html中的Session
原文地址:http://www.cnblogs.com/1439107348s/p/7859732.html