asp JavaScript倒计时问题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了asp JavaScript倒计时问题相关的知识,希望对你有一定的参考价值。
我做了一个在线考试系统,里面想设置倒计时显示,我的思路如下,只是它只能设置一个日期才能有效,比如距离2009年1月1日还有多长时间,可是我想要设置具体的一段时间,比如考试时间为30分钟,如何修改?或者哪位朋友帮我重写一个,写好了我多加分,感激不尽!
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<DIV class=newsItem><B><ALIGN=CENTER><FONT color=blue>距离新年还有</B></FONT> <SPAN id=span_dt_dt style="BACKGROUND-COLOR: #ffffff; align: center no:1px solid black"></SPAN>
<SCRIPT language=javascript>
<!--
//document.write("");
function show_date_time()
BirthDay=new Date("1-1-2009");//这个日期是可以修改的
today=new Date();
timeold=(BirthDay.getTime()-today.getTime());
sectimeold=timeold/1000
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000
e_daysold=timeold/msPerDay
daysold=Math.floor(e_daysold);
e_hrsold=(e_daysold-daysold)*24;
hrsold=Math.floor(e_hrsold);
e_minsold=(e_hrsold-hrsold)*60;
minsold=Math.floor((e_hrsold-hrsold)*60);
seconds=Math.floor((e_minsold-minsold)*60);
span_dt_dt.innerHTML="<b><align=center><font color=blue>"+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒"+"</b><br></font>" ;
show_date_time();
//-->
</SCRIPT>
</DIV>
</body>
</html>
谢谢大家,我已经自己实现了,可是怎么防止考生刷新啊,每次刷新都会重新计时!
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script>
var timeLeft = 30 * 60 * 1000; //30是设定的时间,代表30分钟
function countTime()
if(timeLeft == 0)
alert("时间到!");
return;
var startMinutes = parseInt(timeLeft / (60 * 1000), 10);
var startSec = parseInt((timeLeft - startMinutes * 60 * 1000)/1000)
document.body.innerText = "离考试结束还有:" + startMinutes + "分钟" + startSec + "秒";
timeLeft = timeLeft - 1000;
setTimeout('countTime()',1000);
</script>
<body onload="countTime()">
</body>
</html> 参考技术B <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<DIV class=newsItem><B><ALIGN=CENTER><FONT color=blue>距离新年还有</B></FONT> <SPAN id=span_dt_dt style="BACKGROUND-COLOR: #ffffff; align: center no:1px solid black"></SPAN>
<SCRIPT language=javascript>
<!--
//BirthDay=new Date("1-1-2009");
BirthDay=new Date();//这个日期是可以修改的
BirthDay.setMinutes(BirthDay.getMinutes()+30);
//document.write("");
function show_date_time()
today=new Date();
timeold=(BirthDay.getTime()-today.getTime());
sectimeold=timeold/1000
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000
e_daysold=timeold/msPerDay
daysold=Math.floor(e_daysold);
e_hrsold=(e_daysold-daysold)*24;
hrsold=Math.floor(e_hrsold);
e_minsold=(e_hrsold-hrsold)*60;
minsold=Math.floor((e_hrsold-hrsold)*60);
seconds=Math.floor((e_minsold-minsold)*60);
span_dt_dt.innerHTML="<b><align=center><font color=blue>"+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒"+"< /b><br></font>" ;
window.setTimeout("show_date_time();",100);
show_date_time();
//-->
</SCRIPT>
</DIV>
</body>
</html>本回答被提问者采纳 参考技术C 你可以将倒计时的时间记录到cookice中去,每次页面打开时从新读这个cookice.
当然也可以记录在ASP的session中去,效果是一样的.
除了这两种办法没第三种!
以上是关于asp JavaScript倒计时问题的主要内容,如果未能解决你的问题,请参考以下文章