gpt4 book ai didi

javascript - 在 Jquery 倒计时器中用当前日期时间替换硬编码日期时间

转载 作者:行者123 更新时间:2023-12-03 07:58:17 25 4
gpt4 key购买 nike

我正在致力于构建一个使用 Jquery 构建的倒计时器 http://www.jqueryscript.net/time-clock/Extremely-Lightweight-jQuery-Countdown-Timer-Plugin-downCount.html 。该脚本有一个硬编码的日期时间。我想将其替换为当前日期时间。我可以使用new Date(),但是偏移量似乎没有影响,因此倒计时器总是立即发出警报。

<script class="source" type="text/javascript">
$('.countdown').downCount({
date: '09/09/2016 12:00:00',
offset: +10
}, function () {
alert('Time Up');
});
</script>

当前日期时间:

<script class="source" type="text/javascript">
$('.countdown').downCount({
date: new Date(),
offset: +10
}, function () {
alert('Time Up');
});
</script>

最佳答案

您是否尝试过将日期作为字符串添加到插件中?:

var date = new Date();
var day = date.getDate();
var month = date.getMonth()+1;
var year = date.getFullYear();
var hour = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();

var dateString = day + '/' + month + '/' + year + ' ' + hour + ':' + minutes + ':' + seconds;

$('.countdown').downCount({
date: dateString,
offset: +10
}, function () {
alert('Time Up');
});

var date = new Date();
var day = date.getDate();
var month = date.getMonth()+1;
var year = date.getFullYear();
var hour = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();

var dateString = day + '/' + month + '/' + year + ' ' + hour + ':' + minutes + ':' + seconds;

$('.countdown').downCount({
date: dateString,
offset: +10
}, function () {
alert('Time Up');
});
ul.countdown {
list-style: none;
margin: 75px 0;
padding: 0;
display: block;
text-align: center;
}
ul.countdown li {
display: inline-block;
}
ul.countdown li span {
font-size: 80px;
font-weight: 300;
line-height: 80px;
}
ul.countdown li.seperator {
font-size: 80px;
line-height: 70px;
vertical-align: top;
}
ul.countdown li p {
color: #a7abb1;
font-size: 14px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://www.jqueryscript.net/demo/Extremely-Lightweight-jQuery-Countdown-Timer-Plugin-downCount/jquery.downCount.js"></script>

<ul class="countdown">
<li> <span class="days">00</span>
<p class="days_ref">days</p>
</li>
<li class="seperator">.</li>
<li> <span class="hours">00</span>
<p class="hours_ref">hours</p>
</li>
<li class="seperator">:</li>
<li> <span class="minutes">00</span>
<p class="minutes_ref">minutes</p>
</li>
<li class="seperator">:</li>
<li> <span class="seconds">00</span>
<p class="seconds_ref">seconds</p>
</li>
</ul>

关于javascript - 在 Jquery 倒计时器中用当前日期时间替换硬编码日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34707417/

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