HTML5中的Web Storage

Author: 刘老师(Aaron Lau) 武汉长乐教育,武汉PHP培训课程,版权所有,转载请注明!

HTML5中的Web Storage

本课摘要

  1. localStorage
  2. sessionStorage
  3. localStorage与sessionStorage的区别

1. localStorage

localStorage.setItem(name= "aaron");
alert(localStorage.getItem("name"));

简化写法

localStorage.name= "aaron";
alert(localStorage.name);

删除

localStorage.removeItem(key);
localStorage.clear();

2. sessionStorage

sessionStorage.setItem(name= "aaron");
alert(sessionStorage.getItem("name"));

简化写法

sessionStorage.name= "aaron";
alert(sessionStorage.name);

3. localStorage与sessionStorage的区别

sessionStorage localStorage
窗口或标签页关闭失效 持久储存
只在当前窗口或标签页可见 同源窗口或标签页共享
上一篇课程 下一篇课程

学生登录