在jsp页面上如何写一个倒计时?
正在做一个考试的页面,要考虑到倒计时提醒交卷,而且中途可以退出并保存考试下次再考,要计算时间来进行倒计时,还要考虑页面刷新的问题。100分,有代码继续追加。...
正在做一个考试的页面,要考虑到倒计时提醒交卷,而且中途可以退出并保存考试下次再考,要计算时间来进行倒计时,还要考虑页面刷新的问题。 100分,有代码继续追加。
展开
3个回答
展开全部
用js控制,不用刷新页面,给你一个做参考:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<title>实时倒计时</title>
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
</head>
<body>
<!--单位:秒-->
剩余时间:<span id="endtime">10</span>
<script type="text/javascript">
var CID = "endtime";
if(window.CID != null)
{
var iTime = document.getElementById(CID).innerText;
var Account;
RemainTime();
}
function RemainTime()
{
var iDay,iHour,iMinute,iSecond;
var sDay="",sHour="",sMinute="",sSecond="",sTime="";
if (iTime >= 0)
{
iDay = parseInt(iTime/24/3600);
if (iDay > 0)
{
sDay = iDay + "天";
}
iHour = parseInt((iTime/3600)%24);
if (iHour > 0){
sHour = iHour + "小时";
}
iMinute = parseInt((iTime/60)%60);
if (iMinute > 0){
sMinute = iMinute + "分钟";
}
iSecond = parseInt(iTime%60);
if (iSecond >= 0){
sSecond = iSecond + "秒";
}
if ((sDay=="")&&(sHour=="")){
sTime="<span style='color:darkorange'>" + sMinute+sSecond + "</font>";
}
else
{
sTime=sDay+sHour+sMinute+sSecond;
}
if(iTime==0){
clearTimeout(Account);
sTime="<span style='color:green'>时间到了!</span>";
}
else
{
Account = setTimeout("RemainTime()",1000);
}
iTime=iTime-1;
}
else
{
sTime="<span style='color:red'>倒计时结束!</span>";
}
document.getElementById(CID).innerHTML = sTime;
}
</script>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<title>实时倒计时</title>
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
</head>
<body>
<!--单位:秒-->
剩余时间:<span id="endtime">10</span>
<script type="text/javascript">
var CID = "endtime";
if(window.CID != null)
{
var iTime = document.getElementById(CID).innerText;
var Account;
RemainTime();
}
function RemainTime()
{
var iDay,iHour,iMinute,iSecond;
var sDay="",sHour="",sMinute="",sSecond="",sTime="";
if (iTime >= 0)
{
iDay = parseInt(iTime/24/3600);
if (iDay > 0)
{
sDay = iDay + "天";
}
iHour = parseInt((iTime/3600)%24);
if (iHour > 0){
sHour = iHour + "小时";
}
iMinute = parseInt((iTime/60)%60);
if (iMinute > 0){
sMinute = iMinute + "分钟";
}
iSecond = parseInt(iTime%60);
if (iSecond >= 0){
sSecond = iSecond + "秒";
}
if ((sDay=="")&&(sHour=="")){
sTime="<span style='color:darkorange'>" + sMinute+sSecond + "</font>";
}
else
{
sTime=sDay+sHour+sMinute+sSecond;
}
if(iTime==0){
clearTimeout(Account);
sTime="<span style='color:green'>时间到了!</span>";
}
else
{
Account = setTimeout("RemainTime()",1000);
}
iTime=iTime-1;
}
else
{
sTime="<span style='color:red'>倒计时结束!</span>";
}
document.getElementById(CID).innerHTML = sTime;
}
</script>
</body>
</html>
展开全部
页面显示可以用javascript来做,同时记录点击开始的时间,保存到数据库,退出的时候将退出时间与开始时间做比较,保存剩余时间,下此再开始时,从数据库取剩余时间,用脚本js展示
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询