ASP网页倒计时
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ASP网页倒计时相关的知识,希望对你有一定的参考价值。
打开一个网页,开始一个6小时的倒计时,即“剩余时间XX小时XX分钟XX秒”的格式。
能过javascript来实现,使用setTimeout函数来计时,每一秒执一下自定义函ShowTime2用来显示新的时间。
<html>
<head>
<title>倒计时</title>
<script language="javascript" type="text/javascript">
var time;
var minutes;
var seconds;
var str;
function ShowTime2()
time = document.getElementById("hidTime").value;
time = time - 1;
document.getElementById("hidTime").value = time;
minutes = parseInt(time / 60);
seconds = time % 60;
document.getElementById("DjTimeDiv").innerHTML = "剩余时间:" + minutes + "分钟" + seconds + "秒";
if (time == 1)
document.getElementById("DjTimeDiv").innerHTML="剩余时间:0分钟0秒";
document.getElementById ("btnSubmitExam").click();
else
setTimeout("ShowTime2()", 1000);
</script>
</head>
<body>
<div id="DjTimeDiv"> </div>
<input type="button" value="开始计时" onclick="ShowTime2() ">
<input type="hidden" value="2700" id="hidTime">
</body>
</html>
说明:
定义和用法
setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式。
语法
setTimeout(code,millisec)
提示和注释
提示:setTimeout() 只执行 code 一次。如果要多次调用,请使用 setInterval() 或者让 code 自身再次调用 setTimeout()。
参考技术A 临时写了一个最精简版的,关键地方有注释,也发到你邮箱了。希望对你有帮助。<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>网页倒计时</title>
<style type="text/css">
<!--
.timer margin:0 auto; width:300px; height:50px; background:#FFFAF0; border:#F90 1px solid;
.timer_label width:150px; height:50px; line-height:50px; float:left; text-align:right; color:#090; font-weight:bold;
.timer_time width:148px; height:50px; line-height:50px; color:#F00; font-weight:bold;
-->
</style></head>
<script>
var timer_id = 0;
var counter_hour = 1;//这儿设置倒计时的小时数
var counter_second = 0;
function timer_t(timer_cur)
var timer = document.getElementById("timer");
//初始化,把小时转成总秒数
if(timer_cur == "")
timer_cur = counter_hour * 60 * 60;
//将总秒数转换为时分秒
hour = parseInt(timer_cur / (60 * 60));
minute = parseInt((timer_cur / 60 % 60));
second = parseInt(timer_cur % 60);
//分秒,当为一位数时前面补0
minute = ((minute < 10)?"0":"") + minute;
second = ((second < 10)?"0":"") + second;
//显示到网页上
timer.innerHTML = hour + "时" + minute + "分" + second + "秒";
//递归显示时间
timer_cur --;
clearInterval(timer_id);
if(timer_cur >= 0)
timer_id = setInterval("timer_t("+timer_cur+")" , 1000);
</script>
<body onload="timer_t('')">
<div class="timer">
<div class="timer_label">剩余时间:</div>
<div class="timer_time" id="timer"></div>
</div>
</body>
</html>本回答被提问者采纳
以上是关于ASP网页倒计时的主要内容,如果未能解决你的问题,请参考以下文章