x
 
<!DOCTYPE html>
<html>
<head>
<script>
function clickCounter() {
  if(typeof(Storage) !== "undefined") {
    if (sessionStorage.clickcount) {
      sessionStorage.clickcount = Number(sessionStorage.clickcount)+1;
    } else {
      sessionStorage.clickcount = 1;
    }
    document.getElementById("result").innerHTML = "You have clicked the button " + sessionStorage.clickcount + " time(s) in this session.";
  } else {
    document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";
  }
}
</script>
</head>
<body>
<p><button onclick="clickCounter()" type="button">点击我!</button></p>
<div id="result"></div>
<p>单击按钮来查看计数器增加。</p>
<p>关闭浏览器选项卡(或窗口),然后重试,计数器将被重置。</p>
</body>
</html>