In Chrome funktioniert das gut, aber in IE und Firefox bekomme ich NaN zurück. Jede Hilfe ist willkommen.Math.floor gibt NaN zurück
Grundsätzlich soll dies eine einfache Countdown-Funktion sein. Wenn ich das auch falsch mache, lass es mich wissen.
var start_date = "09 Sep 16";
var end = new Date(start_date); // set expiry date and time..
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) {
// handle expiry here..
clearInterval(timer); // stop the timer from continuing ..
alert('Expired'); // alert a message that the timer has expired..
return; // break out of the function so that we do not update the counters with negative values..
}
var days = Math.floor(distance/_day);
document.getElementById('date').innerHTML = ' ' + days + ' ';
}
timer = setInterval(showRemaining, 1000);
Count down: <div id="date"></div>
Wo sehen Sie rufen tatsächlich 'showRemaining()'? – j08691
Öffnen Sie Ihren Debugger und platzieren Sie einen Breakpoint vor dem 'Math.floor()'. Was sind die Werte von "Abstand" und "_day"? – zero298
Sorry vergessen zu kopieren im setInterval –