任何人都可以編輯此代碼以刪除天和秒,如果它有0值? 我的意思是隻顯示最新左和how to countdown to a dateJavascript倒計時刪除值
感謝
<script>
CountDownTimer('02/19/2012 10:1 AM', 'countdown');
CountDownTimer('02/20/2012 10:1 AM', 'newcountdown');
function CountDownTimer(dt, id)
{
var end = new Date(dt);
var _second = 1000;
var _minute = _second * 60;
var _hour = _minute * 60;
var _day = _hour * 24;
var timer;
function showRemaining() {
var now = new Date();
var distance = end - now;
if (distance < 0) {
clearInterval(timer);
document.getElementById(id).innerHTML = 'EXPIRED!';
return;
}
var days = Math.floor(distance/_day);
var hours = Math.floor((distance % _day)/_hour);
var minutes = Math.floor((distance % _hour)/_minute);
var seconds = Math.floor((distance % _minute)/_second);
document.getElementById(id).innerHTML = days + 'days ';
document.getElementById(id).innerHTML += hours + 'hrs ';
document.getElementById(id).innerHTML += minutes + 'mins ';
document.getElementById(id).innerHTML += seconds + 'secs';
}
timer = setInterval(showRemaining, 1000);
}
</script>
<div id="countdown"></div>
<div id="newcountdown"></div>
你試一下訪問的元素或者你只是想避免學習JavaScript? –
你是否親自嘗試過這樣做? –
我做了,它沒有工作,倒計時不會顯示。 :( – wmsgeek