有人可以帮我添加一个前导零做我的倒计时 JavaScript。尝试了 3 个小时,现在我快疯了……这是干净的倒计时,没有我做过的任何奇怪的编码:
<script type="text/javascript">
var strTargetDate = "05/16/2014 12:00 AM";
var strFormat = "$DAYS$ $HOURS$ $MINUTES$ $SECONDS$";
var strExpired = "DONE";
function doCountDown(seconds)
{
if (seconds < 0)
{
document.getElementById("countdown").innerHTML = strExpired;
return;
}
var strMsg = strFormat;
strMsg = strMsg.replace("$DAYS$", ((Math.floor(seconds/86400))%100000).toString());
strMsg = strMsg.replace("$HOURS$", ((Math.floor(seconds/3600))%24).toString());
strMsg = strMsg.replace("$MINUTES$", ((Math.floor(seconds/60))%60).toString());
strMsg = strMsg.replace("$SECONDS$", ((Math.floor(seconds))%60).toString());
document.getElementById("countdown").innerHTML = strMsg;
setTimeout("doCountDown(" + (seconds-1).toString() + ")", 1000);
}
function initCountDown()
{
var dtTarget = new Date(strTargetDate);
var dtNow = new Date();
var dtDiff = new Date(dtTarget-dtNow);
var totalSeconds = Math.floor(dtDiff.valueOf()/1000);
doCountDown(totalSeconds);
}
initCountDown();
</script>