实例:刷新值会增长,关掉浏览器,再打开,值会在原基础上增长
if(localStorage.pagecount){ localStorage.pagecount=Number(localStorage.pagecount)+1; }else{ localStorage.pagecount=1; } document.write(localStorage.pagecount);
设置和取值两种方法:
1、操作dot
设值 localStorage.hello = ‘world‘; localStorage.zhangsan = ‘lisi‘; 取值: var value_of_hello_in_localStorage = localStorage.hello; var value_of_zhangsan_in_localStorage = localStorage.zhangsan
2、get setItem
设值: localStorage.setItem("hello", "world"); localStorage.setItem("zhangsan", "lisi"); 取值: localStorage.getItem("hello"); localStorage.getItem("zhangsan");
时间: 2024-10-11 02:23:53