gpt4 book ai didi

javascript - jquery倒计时年月日

转载 作者:行者123 更新时间:2023-12-03 06:07:38 24 4
gpt4 key购买 nike

我在 jQuery 中有这个倒计时,但是月份和日期没有显示正确的数字。错误在于月份和日期的计算:

seconds / (60 * 60 * 24 * 30.41666666 * 12)

这是 Jquery:

(function($)  {

$.fn.countdown = function(options, callback) {

var settings = { 'date': null }

if (options) {
$.extend(settings, options)
}

this_sel = $(this);

function count_ecec() {
eventDate = Date.parse(settings['date']) / 1000;
currentDate = Math.floor( $.now() / 1000 );

if (eventDate <= currentDate ) {
callback.call(this);
clearInterval(interval);
}

seconds = eventDate - currentDate;

if (this_sel.find('.years').length > 0) {
years = Math.floor( seconds / ( 60 * 60 * 24 * 30.41666666 * 12 ) );
seconds -= years * 60 * 60 * 24 * 30.41666666 * 12 ;
}

if (this_sel.find('.days').length > 0) {
days = Math.floor( seconds / ( 60 * 60 * 24 * 30.41666666 ) );
seconds -= days * 60 * 60 * 24 * 30.41666666;
}
if (this_sel.find('.month').length > 0) {
month = Math.floor( seconds / ( 60 * 60 * 24 ) );
seconds -= month * 60 * 60 * 24 ;
}
if (!isNaN(eventDate)) {
if (this_sel.find('.years').length > 0) {
this_sel.find('.years').text(years);
}
if (this_sel.find('.days').length > 0) {
this_sel.find('.days').text(days);
}
if (this_sel.find('.month').length > 0) {
this_sel.find('.month').text(month);
}
}
}
count_ecec();
interval = setInterval(count_ecec, 1000);
}

}) (jQuery);

这是 HTML:

 <div class="large-5 large-centered columns counter">                       
<div class="container">
<div id="countdown">
<div class="large-4 columns">
<span>Día</span>
<span class="days"></span>
</div>
<div class="large-4 columns">
<span>Mes</span>
<span class="month"></span>
</div>
<div class="large-4 columns">
<span>Año</span>
<span class="years"></span>
</div>
</div>
</div>
</div>

<script src="js/countdown.js" charset="utf-8"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#countdown').countdown({date: '15/12/2016'}, function() {
$('#countdown').text('');
});
});
</script>

最佳答案

我认为你的几天和几个月的方程式颠倒了......

days = Math.floor( seconds / ( 60 * 60 * 24 * 30.41666666 ) );

应该是

months = Math.floor( seconds / ( 60 * 60 * 24 * 30.41666666 ) );

关于javascript - jquery倒计时年月日,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39461566/

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