<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript" src="../js/jquery-3.2.1.min.js"></script>
<script>
$(function () {
//判断该sessionStorage的key是否存在
if (sessionStorage.getItem("num1") != null) {
//存在,把SessionStorage里的value值赋值到页面
$("#span1").html(sessionStorage.getItem("num1"));
}
//触发点击事件
$("#btn").click(function () {
//获取页面id=span1的值
var num = $("#span1").html();
//判断该sessionStorage的key是否存在
if (sessionStorage.getItem("num1") != null) {
//获取SessionStorage里的value值
num = sessionStorage.getItem("num1");
}
num++;
//把增加后的num值存储到sessionStorage里
sessionStorage.setItem("num1", num);
//把增加后的num值显示到页面
$("#span1").html(num);
})
})
</script>
</head>
<body>
<span id="span1">0</span><input type="button" id="btn" value="点击">
</body>
</html>