展开全部
能过Javascript来实现,使用setTimeout函数来计时,每一秒执一下自定义函ShowTime2用来显示新的时间。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<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()。
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
展开全部
临时写了一个最精简版的,关键地方有注释,也发到你邮箱了。希望对你有帮助。
<!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>
<!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>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询