当前位置: 代码迷 >> JavaScript >> js做的 记时
  详细解决方案

js做的 记时

热度:429   发布时间:2013-12-13 13:57:17.0
js做的 倒计时
源:http://blog.csdn.net/jaycxing/article/details/5866655  代码有问题
评:


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>

<script>


var timeID = null;




function showtime() {
today = new Date();
var nowHour = today.getHours();
var nowMinute = today.getMinutes();
var nowSecond = today.getSeconds();

var nowDate = today.getDate();


if(nowDate >= 12 && nowHour >= 10 && nowMinute >= 0 && nowSecond >= 0) {
secondleft = "00";
minuteleft = "00";
hourleft = "00";
dateleft = "00";

$("#day").html(dateleft);
$("#hour").html(hourleft);
$("#minute").html(minuteleft);
$("#second").html(secondleft);

return;
}
hourleft = 10 - nowHour;
minuteleft = 00 - nowMinute;
secondleft = 00 - nowSecond;

dateleft = 12 - nowDate;


if(secondleft < 0) {
secondleft = 60 + secondleft;
minuteleft = minuteleft -1;
}
if(minuteleft < 0) {
minuteleft = 60 + minuteleft;
hourleft = hourleft - 1;
}
if(hourleft < 0) {
hourleft = 24 + hourleft;
dateleft = dateleft -1;
}

if(secondleft < 1 && minuteleft < 1 && hourleft < 1 && dateleft < 1) {
clearTimeout(timeID);
}

else {
timerID = setTimeout("showtime()", 1000);
}

if(secondleft <10) {
secondleft = "0" + secondleft;
}
if(minuteleft <10) {
minuteleft = "0" + minuteleft;
}
if(hourleft <10) {
hourleft = "0" + hourleft;
}
if(dateleft <10) {
dateleft = "0" + dateleft;
}

//alert(dateleft + "aa" + hourleft +minuteleft +  secondleft);
$("#day").html(dateleft);
$("#hour").html(hourleft);
$("#minute").html(minuteleft);
$("#second").html(secondleft);
//alert(dateleft + "-" + hourleft + "-" + minuteleft + "-" + secondleft);


//timerRunning = true;
}



</script>


</head>

<body onload="showtime();">
  相关解决方案