2017-04-14 28 views
0

首先,我使用jalali/persian日期和倒計時jQuery插件不適用於我。對於ex插件,必須輸入格式如2017/5/2,但波斯/加拉里日期爲1396/2/17。在一頁中多次倒計時

我有指定日,小時,分和秒的多個日期時間。例如:

3天13小時4分鐘25秒

23天2小時41分鐘3秒...

我有天,小時,分鐘和秒的單獨的,

我想倒計時他們在一個頁面日期(他們的日期數量daynamic)

我用這個代碼,做工精細,當只在一個頁面日期

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/

任何人都可以幫我嗎?

回答

0

你只需要確定包裝元素爲每一個這樣的:

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

然後在你的元素選擇前使用$(本).find()。這將把函數綁定到倒數的每個實例。目前它只是尋找類「天」,所以它只會使用它找到的第一個,或導致其他錯誤。我會很快寫一個工作的例子。

我不確定數字,但他們似乎是在這裏獨立運行(設置超時爲較少的調試)https://jsfiddle.net/7nzcdhn3/