下面是一个例子:
localStorage和sessionStorage 是window对象,他们都实现了Storage接口
参考文档:
http://www.w3.org/TR/2011/CR-webstorage-20111208/
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<script type="text/javascript">
var i=localStorage.pagecount;
if(i){
localStorage.pagecount=Number(i)+1;
}else{
localStorage.pagecount=1;
}
document.write("local:"+localStorage.pagecount);
var j=sessionStorage.pagecount;
if(j){
sessionStorage.get.pagecount=Number(j)+1;
}else{
sessionStorage.pagecount=1;
}
document.write("session:"+sessionStorage.pagecount);
</script>
</body>
</html>
localStorage和sessionStorage 是window对象,他们都实现了Storage接口
interface Storage {
readonly attribute unsigned long length;
DOMString? key(unsigned long index);
getter DOMString getItem(DOMString key);
setter creator void setItem(DOMString key, DOMString value);
deleter void removeItem(DOMString key);
void clear();
};
参考文档:
http://www.w3.org/TR/2011/CR-webstorage-20111208/
本文深入解析localStorage和sessionStorage的区别,并通过一个示例代码展示它们的使用方式,帮助开发者更好地掌握这两项Web存储技术。
1914

被折叠的 条评论
为什么被折叠?



