首先,我使用 jalali/波斯日期和倒计时 jQuery 插件对我不起作用。对于 ex 插件必须输入公历日期,例如 2017/5/2 但波斯/贾拉利日期是 1396/2/17 。
我有指定日期、小时、分钟和秒的多个日期时间。前任:
3天13小时4分25秒
23 天 2 小时 41 分 3 秒 ...
我有天、小时、分和秒分开,
我想在一页中倒计时他们的日期(他们的日期数是自然的)
当页面中只有一个日期时,我使用此代码并且工作正常
html:
<div class="row">
@{TimeSpan span = (item.DiscountExpireDate - DateTime.Now);}
<ul class="countdown">
<li>
<span class="seconds">@span.Seconds</span>
<p class="seconds_ref">ثانیه</p>
</li>
<li class="seperator">:</li>
<li>
<span class="minutes">@span.Minutes</span>
<p class="minutes_ref">دقیقه</p>
</li>
<li class="seperator">:</li>
<li>
<span class="hours">@span.Hours</span>
<p class="hours_ref">ساعت</p>
</li>
<li class="seperator"> </li>
<li>
<span class="days">@span.Days</span>
<p class="days_ref">روز</p>
</li>
</ul>
</div>
和js
<script type="text/javascript">//for countdown
$(document)
.ready(function () {
var theDaysBox = $(".days");
var theHoursBox = $(".hours");
var theMinsBox = $(".minutes");
var theSecsBox = $(".seconds");
var refreshId = setInterval(function() {
var currentSeconds = theSecsBox.text();
var currentMins = theMinsBox.text();
var currentHours = theHoursBox.text();
var currentDays = theDaysBox.text();
if (currentSeconds == 0 && currentMins == 0 && currentHours == 0 && currentDays == 0) {
// if everything rusn out our timer is done!!
// do some exciting code in here when your countdown timer finishes
} else if (currentSeconds == 0 && currentMins == 0 && currentHours == 0) {
// if the seconds and minutes and hours run out we subtract 1 day
theDaysBox.html(currentDays - 1);
theHoursBox.html("23");
theMinsBox.html("59");
theSecsBox.html("59");
} else if (currentSeconds == 0 && currentMins == 0) {
// if the seconds and minutes run out we need to subtract 1 hour
theHoursBox.html(currentHours - 1);
theMinsBox.html("59");
theSecsBox.html("59");
} else if (currentSeconds == 0) {
// if the seconds run out we need to subtract 1 minute
theMinsBox.html(currentMins - 1);
theSecsBox.html("59");
} else {
theSecsBox.html(currentSeconds - 1);
}
},
1000);
});
</script>
但是当我在页面上有多个日期时效果不佳,而且数字似乎加在一起。
https://jsfiddle.net/a7ucv468/1/
任何人都可以帮助我吗?