注意:要在同一域名下的页面才有效

在需要存储数据页面用localStorage设置数据

localStorage.setItem(key,value);//key要用单引号或者双引号包括着,value就是你要存的数据

在需要引用数据的页面用localStorage获取数据

var name=localStorage.getItem(key);//key要用单引号或者双引号包括着,用一变量存起来方便使用

删除数据,因为localStorage是可长期存储数据的,所以如果用完后不再需要的话,可以顺手销毁掉

localStorage.removeItem(key);//删除单个数据
localStorage.clear();//删除所有数据
localStorage.key(index);//得到某个索引的key

 

相关文章:

  • 2022-01-12
  • 2022-02-11
  • 2021-12-15
  • 2021-07-26
  • 2021-10-14
  • 2021-07-30
  • 2021-06-16
  • 2022-01-15
猜你喜欢
  • 2021-06-25
  • 2021-10-27
  • 2021-06-10
  • 2022-12-23
  • 2021-05-15
  • 2022-12-23
相关资源
相似解决方案