<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
//新建对象
localStorage.name="学习html5新技术-本地存储:";
document.write(localStorage.name);
//访问网站计数
if(localStorage.count)
localStorage.count=Number(localStorage.count)+1;
else
localStorage.count=1;
document.write("您访问此网站的次数为"+localStorage.count+"<br />");
//获取并显示数据,遍历数据
var array=new Array();
for(var i=0,len=localStorage.length;i<len;i++){
//key为保存数据时的键名项
var key=localStorage.key(i);
//value为键名项所对应的值
var value=localStorage.getItem(key);
array=value.split(",");
}
document.write(localStorage.length+"<br />");
for(var i=0;i<localStorage.length;i++){
document.write(array[i]+"<br />");
}
//保存数据
console.log(key+"="+value);
// localStorage.clear();//清空localStorage数据
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
//新建对象
localStorage.name="学习html5新技术-本地存储:";
document.write(localStorage.name);
//访问网站计数
if(localStorage.count)
localStorage.count=Number(localStorage.count)+1;
else
localStorage.count=1;
document.write("您访问此网站的次数为"+localStorage.count+"<br />");
//获取并显示数据,遍历数据
var array=new Array();
for(var i=0,len=localStorage.length;i<len;i++){
//key为保存数据时的键名项
var key=localStorage.key(i);
//value为键名项所对应的值
var value=localStorage.getItem(key);
array=value.split(",");
}
document.write(localStorage.length+"<br />");
for(var i=0;i<localStorage.length;i++){
document.write(array[i]+"<br />");
}
//保存数据
console.log(key+"="+value);
// localStorage.clear();//清空localStorage数据
</script>
</body>
</html>