localStorage和sessionStorage
- 区别是存储的时间不同 时效不同
- localStorage 永久保存 除非手动删除 5m
- sessionStorage 仅保存当前会话 只要会话关闭就删除
- cookie 设置过期时间 4k
API
存:
- localStorage.setItem("名","值")
- localStorage."名" = "值"
- localStorage["名"] = "值"
取:
- localStorage.getItem("名")
- localStorage."名"
- localStorage["名"]
删:
- localStorage.removeItem("名")
- localStorage.clear()
- localStorage.hasOwnProperty("名") 判断当前有没有这个名,返回boolean