JSP页面显示倒计时

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<html>
<head>
<title>标题页</title>
<meta http-equiv="refresh" content="11; url=2.jsp">
<script language="JavaScript">
//获取当前时间
startday=new Date();
clockStart=startday.getTime();
function initStopwatch(){
	var myTime=new Date();
	var timeNow=myTime.getTime();
	var timeDiff=timeNow-clockStart;//获取间隔时间
	this.diffSecs=timeDiff/1000; //时间以毫秒为单位
	return(this.diffSecs);
}
function getSecs(){
	var mySecs=initStopwatch();
	var mySecs1=""+mySecs;
	var time = parseInt(mySecs1);

	var h = (time/3600); 
	var h1 = ""+h;
	var h2 = parseInt(h1);

	var m = ((time-3600*h2)/60);
	var m1 = ""+m;
	var m2 = parseInt(m1);

	var s = (time-3600*h2-60*m2);
	var s1 = ""+s;
	var s2 = parseInt(s1);

	var t = h2+"时"+m2+"分"+s2+"秒";
	document.form1.timespent.value=t;
	window.setTimeout('getSecs()',1000);
}
</script>
</head>
<body bgcolor="#ffffff" onLoad="window.setTimeout('getSecs()',1)">
<center>
10秒后加载页面:
<form name=form1><input size=90 name=timespent></form>
</center>
</body>
</html>

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。