Js实现倒计时效果
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Js实现倒计时效果</title>
<script language="javascript">
var timeLeft = 1 * 3 * 1000;//这里设定的时间是90秒
function countTime(){
if(timeLeft == 0){//这里就是时间到了之后应该执行的动作了,这里只是弹了一个警告框
var msg = "门户系统会话失效,需要重新登录,请确认?";
if (confirm(msg)==true){
var logoutUrl = "./oauthLogout.do";
window.location.replace(logoutUrl);//页面刷新
return;
}else{
timeLeft = 1 * 3 * 1000;//这里设定的时间是90秒
}
}
var startMinutes = parseInt(timeLeft / (60 * 1000), 10);
var startSec = parseInt((timeLeft - startMinutes * 60 * 1000)/1000);
document.getElementById('show').innerHTML = "剩余时间:" + startMinutes + "分钟" + startSec + "秒";
timeLeft = timeLeft - 1000;
setTimeout('countTime()',1000);
}
</script>
</head>
<body onload="countTime()">
<div id="show"></div>
</body>
</html>
最近访问时间:2024-09-12 04:27:52