日期:2014-05-16 浏览次数:20439 次
function begin(totalTime){
var begin=new Date();
var hourB = begin.getHours();
var minuteB=begin.getMinutes();
var secondB=begin.getSeconds();
//截止时间
var deadline = new Date();
var hourD = hourB+totalTime/60;
var minuteD = minuteB+totalTime%60;
var secondD=secondB;
//alert("开始时间:"+hourB+":"+minuteB+":"+secondB+"结束时间:"+hourD+":"+minuteD+":"+secondD);
timer = setInterval("countDown(hourD,minuteD,secondD)", 1000);
}
//倒计时
function countDown(hourD,minuteD,secondD) {
var now=new Date();
var hour = now.getHours();
var minute=now.getMinutes();
var second=now.getSeconds();
var leftTime=(hourD-hour)*60*60+(minuteD-minute)*60+(secondD-second);//单位:秒
//alert("剩余时间:"+leftTime);
if (leftTime >= 0) {
minutes = Math.floor(leftTime / 60);
seconds = Math.floor(leftTime % 60);
msg = minutes + "分" + seconds + "秒";
document.all["timer"].innerHTML = msg;
if (leftTime == 5 * 60)
alert('注意,还有5分钟!');
--leftTime;
} else {
clearInterval(timer);
alert("时间到,结束!");
}
}