**
防刷新倒计时
**
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="/spa/lib/js/jquery-3.3.1.min.js"></script>
<title>Document</title>
</head>
<body>
<p id="ip"></p>分<p id="ip1"></p>秒
<script>
$(function() {
console.log("1")
var p = document.getElementById("ip");
var p1 = document.getElementById("ip1");
var sum;
var tmer;
let time = localStorage.getItem("time")
localStorage.clear()
console.log("2")
if (time == null || time == undefined) {
sum = 120
console.log("3")
tm()
} else {
console.log("4")
sum = time
tm()
}
function format(a)
{
return a.toString().replace(/^(\d)$/,'0$1');
}
function tm() {
console.log("5")
tmer = setTimeout(tm, 1000)
sum--;
p.innerHTML = format(parseInt(sum / 60));
p1.innerHTML = format(parseInt(sum % 60));
localStorage.setItem("time", sum)
if (sum < 1) {
localStorage.clear()
clearTimeout(tmer)
}
}
});
</script>
</body>
</html>