-------还有多少时,分,秒-----------
var dateTmpStart= new Date().getTime();
var exam_now = new Date(dateTmpStart);
function getServerTime()
{
var dateTmpEnd=GetCookie('ckTimeEnd');
dateTmpEnd=dateTmpEnd.replace('+',' ');
var urodz = new Date(dateTmpEnd);
var time_str = "";
var time_str_pre = "距本次考试结束还剩:";
exam_now.setTime(exam_now.getTime()+1000);
time_phase = urodz - exam_now;
if ( time_phase<=0 )
{
time_str = time_str_pre + "0秒";
need_get = 0;
clearInterval(check_time); //卸载setInterval
}
else
{
hours = (urodz - exam_now) / 1000 / 60 / 60;
hoursRound = Math.floor(hours);
minutes = (urodz - exam_now) / 1000 /60 - (60 * hoursRound);
minutesRound = Math.floor(minutes);
seconds = (urodz - exam_now) / 1000 - (60 * 60 * hoursRound) - (60 * minutesRound);
secondsRound = Math.round(seconds);
if( hoursRound !=0 )
{
time_str = time_str_pre + hoursRound + "时" + minutesRound + "分" + secondsRound + "秒";
}
else if ( minutesRound!=0 )
{
time_str = time_str_pre + minutesRound + "分" + secondsRound + "秒";
}
else
{
time_str = time_str_pre + secondsRound + "秒";
}
}
document.getElementById("time").innerHTML = time_str;
}
-------
<script language="JavaScript" type="text/javascript">
check_time = setInterval("getServerTime()",1000);
</script>
<span id="time" style="color:Red;"></span>
------------时间累计--------------------------------------------------------------
var i=0;
var time=0;
function totalTime()
{
document.getElementById("totalTime").innerHTML=time+i;
i++;
}
timer=setInterval('totalTime()',1000);
<span id="totalTime" style="color:Red;"></span>
---------到达一定时间后,跳转到某页--------------------------------------------------
<script language="JavaScript" type="text/jscript">
<!--
var time = 30; //时间,秒
var URL="<%=UrlStr %>";
function Redirect(){
window.location = URL;
}
var i = 0;
function dis(){
document.all.Span1.innerHTML = "还剩 " + (time - i) + " 秒";
i++;
}
timer=setInterval('dis()', 1000);//显示时间
timer=setTimeout('Redirect()',time * 1000); //跳转
//-->
</script>
<span id="Span1" style="color:Red;"></span>