gpt4 book ai didi

php - 想要停止倒计时并随着时间的推移给出输出

转载 作者:行者123 更新时间:2023-11-28 16:12:02 27 4
gpt4 key购买 nike

你好,我想当我的倒计时结束时,它应该显示为:

document.getElementById("remain").innerHTML = "Time up";

此处实时倒计时:http://ffsng.deewayz.in/counter/

由于它即将结束,我想发出“时间到了”

我尝试了一些方法,但没有成功。

function setCountDown() {
seconds--;
if (seconds < 0) {
minutes--;
seconds = 59;
}
if (minutes < 0) {
hours--;
minutes = 59;
}
if (hours < 0) {
days--;
hours = 23;
}
document.getElementById("remain").innerHTML = days + " days, " + hours + " hours, " + minutes + " minutes, " + seconds + " seconds";
if ((seconds = 0) && (minutes = 0) && (hours = 0) && (days = 0))(
document.getElementById("remain").innerHTML = "time up";
) else (
setTimeout("setCountDown()", 1000);
);
}

我的完整代码在这里:Countdown timer not working with gmt time

最佳答案

不太好,但可以满足您的需求!

HTML

<div id="countdown">
<span id="row1"></span><br />
<span id="row2"></span>
</div>

JS

var end = new Date('October 08, 2012 00:55:00');

function toSt1(n) {
var s = '';
if (n < 10) s += '0';
return (s + n).toString();
}

function toSt2(n) {
var s = '';
if (n < 10) s += '00';
else if (n < 100) s += '0';
return (s + n).toString();
}

var countdown = function() {
var d = new Date();
var count = Math.floor(end.getTime() - d.getTime());
if (count > 0) {
var miliseconds = toSt2(count % 1000);
count = Math.floor(count / 1000);
var seconds = toSt1(count % 60);
count = Math.floor(count / 60);
var minutes = toSt1(count % 60);
count = Math.floor(count / 60);
var hours = toSt1(count % 24);
count = Math.floor(count / 24);
var days = count;
document.getElementById('row1').innerHTML = days + ' Days';
document.getElementById('row2').innerHTML = hours + ' Hours ' + minutes + ' Minutes ' + seconds + ' Seconds ';
setTimeout('countdown()', 100);
} else {
document.getElementById("countdown").innerHTML = "Time up";
}
}
countdown();

<强> DEMO

关于php - 想要停止倒计时并随着时间的推移给出输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12603789/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com