码迷,mamicode.com
首页 > Web开发 > 详细

html5:localStorage储存

时间:2015-09-29 08:42:26      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

实例:刷新值会增长,关掉浏览器,再打开,值会在原基础上增长

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");

 

html5:localStorage储存

标签:

原文地址:http://www.cnblogs.com/tinyphp/p/4844628.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!