繁体   English   中英

一页中的多个倒数时间

[英]multiple countdown time in one page

首先,我使用jalali /波斯日期和倒数jQuery插件对我不起作用。 对于前插件,必须输入gregorian日期(如2017/5/2),但波斯语/ jalali日期是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/

有人可以帮助我吗?

您只需要为每个包装元素标识一个包装元素,例如:

$('.countdown").each( function {

然后在元素选择器前面使用$(this).find()。 这会将功能绑定到倒数的每个实例。 当前,它只是在寻找“ days”类,因此它将仅使用找到的第一个类,否则会导致其他错误。 我将尽快写一个工作示例。

我不确定这些数字,但它们似乎在这里独立运行(将超时设置为较小以进行调试) https://jsfiddle.net/7nzcdhn3/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM