如果秒数减到0的时候就减分钟,如果分钟减到零了,那时间就是00:00:00啦<html>
<head>
<title>
count down test!
</title>
</head>
<body>
<input type="text" id="test" />
<script>
var minites = 3;
var second = 0;
var int = windowsetInterval("test()",1000);
function test(){
if(second == 0){
if(minites == 0){
windowclearInterval(int);
}else{
minites--;
second = 59;
}
}else{
second--;
}
if(minites < 10){
mitemp = minites;
minites = "0" + minites;
}
if(second < 10){
setemp = second;
second = "0" + second;
}
var t = minites + ":" + second;
documentgetElementById("test")value = t;
if(minites < 10){
minites = mitemp;
}
if(second < 10){
second = setemp;
}
}
</script>
</body>
</html>
你自己运行一下看看吧,是一个三分钟的倒计时,你看着模仿一下就好。var now = new Date()
var over = new Date(2017,4,18,20,30,00)
var time=(overgetTime())-(nowgetTime())
time=time/1000;//毫秒数转秒数
setInterval (function(){
var day=parseInt(time/60/60/24)
var hour=parseInt(time/60/60%24)
var minute=parseInt(time/60%60)
var second=parseInt(time%60)
time-=1;
consolelog(day+"天"+hour+"时"+minute+"分"+second+"秒")
},1000)希望可以帮到你!
//1前面补0
function p(n){
return n<10'0'+n:n;
}
//2倒计时
function getMyTime(){
var startDate=new Date();
var endDate=new Date('2017/4/17 11:15:00');
var countDown=(endDategetTime()-startDategetTime())/1000;
var day=parseInt(countDown/(246060));
var h=parseInt(countDown/(6060)%24);
var m=parseInt(countDown/60%60);
var s=parseInt(countDown%60);
documentgetElementById('time')innerHTML=day+'天'+p(h)+'时'+p(m)+'分'+p(s)+'秒';
setTimeout('getMyTime()',500);
if(countDown<=0){
documentgetElementById('time')innerHTML='活动结束';
}
}<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 40 Transitional//EN">
<html>
<head>
<meta >
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)