Ich bin neu in Javascript. Mein PHP-Skript gibt einen Wert in diesem FormatJavascript Countdown von d: h: m: s
d:h:m:s
Nun würde Ich mag einen Countdown haben, die in jeder Sekunde von diesem Countdown kann.
Ich habe einen Countdown geändert. Dies funktioniert jedes Mal, wenn der Countdown jede Sekunde "tickt", gibt er NaN die ganze Zeit zurück. Irgendeine Idee, was ich falsch mache?
$(document).ready(function() {
setInterval(function() {
$('.countdown').each(function() {
var time = $(this).data("time").split(':');
var timestamp = time[0] * 86400 + time[1] * 3600 + time[2] * 60 + time[3] * 1;
var days = Math.floor(timestamp/86400);
console.log(time,timestamp);
var hours = Math.floor((timestamp - days * 86400)/3600);
var minutes = Math.floor((timestamp - hours * 3600)/60);
var seconds = timestamp - ((days * 86400) + (hours * 3600) + (minutes * 60))-1;
$(this).data("time",""+days+":"+hours+":"+minutes+":"+seconds);
if (hours < 10) {
hours = '0' + hours;
}
if (minutes < 10) {
minutes = '0' + minutes;
}
if (seconds < 10) {
seconds = '0' + seconds;
}
$(this).text(days + ':' + hours + ':' + minutes + ':' + seconds);
});
}, 1000);
})
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<h1 class="countdown">02:03:05:59</h1>
Wo Sie Zeit Erniedrigen? – itzmukeshy7
'timestamp - = timestamp> 0;' scheint der _culprit _... zu sein – Rayon
Aber es ist nicht. Der größte Täter ist der Inhalt ist nicht mehr dd: hh: mm: ss nach dem Hinzufügen von "Tagen" und so weiter – mplungjan