sessStorage对象是一个会话形式的数据存储,当用户关闭浏览器的窗口后,数据就会被删除。

实例:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta charset="utf-8" />
<style type="text/css"></style>
<script type="text/javascript" src="Css/jquery-2.1.4.js"></script>
<script type="text/javascript">
function myFunction() {
if (typeof (Storage) != "undefined") {
if (sessionStorage.clickCount) {
sessionStorage.clickCount = Number(sessionStorage.clickCount) + 1;
}
else {
sessionStorage.clickCount = 1;
}
document.getElementById("result").innerHTML = sessionStorage.clickCount;
}
else {
document.getElementById("result").innerHTML = "Sorry!,您的浏览器不支持web存储";
}
}

</script>
</head>
<body>
<input type="button" value="点击按钮" onclick="myFunction()" />
<p>点击按钮查看计数器增加</p>
<p>关闭浏览器窗口再一次打开,继续点击按钮,计算器已复位,数据重新开始计数</p>
<p ></p>
</body>
</html>

相关文章:

  • 2022-01-01
  • 2022-12-23
  • 2021-04-18
  • 2022-01-15
  • 2021-08-24
  • 2021-08-19
  • 2022-01-16
猜你喜欢
  • 2022-12-23
  • 2021-06-13
  • 2022-01-31
  • 2021-08-05
  • 2021-07-25
  • 2021-09-03
  • 2021-12-16
相关资源
相似解决方案