<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<script type="text/JavaScript">
var lastMinutes=59;
var lastSeconds=60;
var t,stingTime;
function showTime(){
document.getElementById("hehe").disabled=true;
var allTime=60*60*1000;
lastSeconds--;
if(lastSeconds==0 && lastMinutes==0){
clearTimeout(t);
return;
}
else if(lastSeconds<0){
lastSeconds=59;
lastMinutes--;
}
stringTime="还剩时间为:"+lastMinutes+" : "+lastSeconds;
document.getElementById("timeDiv").innerHTML=stringTime;
setTimeout(showTime,1000);
}
</script> </head>
<body>
<input type='button' value='开始考试' onclick='showTime();' id='hehe'>
<div id='timeDiv'></div>
</body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<script type="text/JavaScript"> var stingTime;
var timeLeft = 10 * 60 * 1000;
var timeLeft1 = 5 * 60 * 1000;
function countTime()
{
document.getElementById("hehe").disabled=true; if(timeLeft == 0)
{
alert("时间到!");
return;
}
var startMinutes = parseInt(timeLeft / (60 * 1000), 10);
var startMinutes1 = parseInt(timeLeft1 / (60 * 1000), 10);
var startSec = parseInt((timeLeft - startMinutes * 60 * 1000)/1000)
document.getElementById("timeDiv").innerHTML = "剩余时间:" + startMinutes + "分钟" + startSec + "秒";
document.getElementById("timeDiv2").innerHTML = "剩余时间:" + startMinutes1 + "分钟" + startSec + "秒";
timeLeft = timeLeft - 1000;
setTimeout('countTime()',1000);
} </script> </head>
<body>
<input type='button' value='开始考试' onclick='countTime();' id='hehe'>
<div id='timeDiv'></div><div id='timeDiv2'></div>
</body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<script type="text/JavaScript"> var stingTime;
var timeLeft = 10 * 60 * 1000;
var timeLeft1 = 5 * 60 * 1000;
function countTime()
{
document.getElementById("hehe").disabled=true; if(timeLeft == 0 || timeLeft1 == 0 )
{
alert("时间到!");
return;
}
var startMinutes = parseInt(timeLeft / (60 * 1000), 10);
var startMinutes1 = parseInt(timeLeft1 / (60 * 1000), 10);
var startSec = parseInt((timeLeft - startMinutes * 60 * 1000)/1000)
document.getElementById("timeDiv").innerHTML = "剩余时间:" + startMinutes + "分钟" + startSec + "秒";
document.getElementById("timeDiv2").innerHTML = "剩余时间:" + startMinutes1 + "分钟" + startSec + "秒";
timeLeft = timeLeft - 1000;
timeLeft1 = timeLeft1 - 1000;
setTimeout('countTime()',1000);
} </script> </head>
<body>
<input type='button' value='开始考试' onclick='countTime();' id='hehe'>
<div id='timeDiv'></div><div id='timeDiv2'></div>
</body> </html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<script type="text/JavaScript">
var lastMinutes=59;
var lastSeconds=60;
var lasts ;
var lastm;
var t,stingTime;
function showTime(){
document.getElementById("hehe").disabled=true;
var allTime=60*60*1000;
lastSeconds--;
if(lastSeconds==0 && lastMinutes==0){
clearTimeout(t);
return;
}
else if(lastSeconds<0){
lastSeconds=59;
lastMinutes--;
}
if(lastSeconds<10)
{
lasts ="0"+lastSeconds;
}
else
lasts =lastSeconds;
if(lastMinutes<10)
{
lastm ="0"+lastMinutes;
}
else{
lastm =lastMinutes;
}
stringTime="还剩时间为:"+lastm+" : "+lasts;
document.getElementById("timeDiv").innerHTML=stringTime;
setTimeout(showTime,1000);
}
</script> </head>
<body>
<input type='button' value='开始考试' onclick='showTime();' id='hehe'><DIV style="background-color:#666666;" >
<IMG src="images/topbar1.gif" /></DIV>
<div id='timeDiv'></div>
</body> </html>
<head>
<meta http-equiv="content-type" content="text/html;charset=gb2312" />
<title>记时器</title>
<script src="timer.js" type="text/javascript"></script>
</head>
<body>
<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>
<script type="text/javascript">
//==========生成记时器,注意生成实例要在你的对象下面,要不会提示“请设置要显示时间的对象!”的错误
new Timer(0,1,0,"div1")
new Timer(0,2,0,"div2")
new Timer(0,0,30,"div3")
</script>
</body>
</html>timer.js
/*
timer.js
---Edit By ShowBo
*/
//===========辅助函数
function FormatNumber(Num){if(Num<10)return "0"+Num;else return Num.toString();}
function $(Id){if(typeof(Id)=="string")return document.getElementById(Id);else return Id;}
//===========
function Timer(hour,minute,second,ObjId)
{
var PackUp=this;
this.hour=hour;
this.minute=minute;
this.second=second;
this.obj=$(ObjId);
if(!this.obj)
{
alert("请设置要显示时间的对象!")
return;
}
this.obj.innerHTML=FormatNumber(this.hour)+":"+FormatNumber(this.minute)+":"+FormatNumber(this.second);
if(hour<1&&minute<1&&second<1)
{
alert("此记时器无效!");
return;
}
this.Go=function()
{
if(this.hour<1&&this.minute<1&&this.second<1)
{
clearInterval(this.timer);
this.timer=null;
alert(ObjId+"记时完成!");
return;
}
this.second--;
if(this.second<1)
{
if(this.minute>0)
{
this.second=59;
this.minute--;
}
else if(this.hour>0)
{
this.minute=59;
this.hour--;
}
}
this.obj.innerHTML=FormatNumber(this.hour)+":"+FormatNumber(this.minute)+":"+FormatNumber(this.second);
}
this.timer=setInterval(function(){PackUp.Go();},1000);
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>倒计时</title>
<style type="text/css">
*{margin:0;padding:0;}
.content{width:300px;margin:0 auto;padding:10px;background:#eee;border:1px solid #999;}
.content p span{color:red;font:bold 20px Arial;}
.content p a{font:12px/23px '宋体';color:#888;}
</style>
</head>
<body>
<div class="content">
<h1>距离</h1> <span></span>
<p>还剩<span id="times"></span></p></div>
<SCRIPT LANGUAGE="JavaScript">
function _fresh(endtime)
{
//var endtime=new Date("2011/8/28,12:20:12");
endtime = new Date(endtime);
var nowtime = new Date();
var leftsecond=parseInt((endtime.getTime()-nowtime.getTime())/1000);
__d=parseInt(leftsecond/3600/24);
__h=parseInt((leftsecond/3600)%24);
__m=parseInt((leftsecond/60)%60);
__s=parseInt(leftsecond%60);
document.getElementById('times').innerHTML = __d+"天 "+__h+"小时"+__m+"分"+__s+"秒"; if(leftsecond<0){
document.getElementById('times').innerHTML = "时间已过";
clearInterval(sh); }
}
var sh;
var endtime = '2011/8/28,12:20:12';//这里设置截至时间,也可以引用ASP或PHP等参数
sh=setInterval('_fresh(endtime)',1000);
</SCRIPT>
</body>
</html>