html5 有两种缓存

1、localStorage:浏览器关闭后,数据库还存在。

2、sessionStorage:session缓存,浏览器关闭后,数据已经不存在。

实例一:localStorage

<!DOCTYPE HTML>
<html>
<body> <script type="text/javascript">
if (localStorage.pagecount)
{
localStorage.pagecount=Number(localStorage.pagecount) +1;
}
else
{
localStorage.pagecount=1;
}
document.write("Visits "+ localStorage.pagecount + " time(s).");
</script>
</body>
</html>

实例二:sessionStorage

<!DOCTYPE HTML>
<html>
<body> <script type="text/javascript"> if (sessionStorage.pagecount)
{
sessionStorage.pagecount=Number(sessionStorage.pagecount) +1;
}
else
{
sessionStorage.pagecount=1;
}
document.write("Visits "+ sessionStorage.pagecount + " time(s).");
</script>
</body>
</html>
04-15 14:50