2017-04-04 102 views
0

我有一個倒計時器,正在鉻操作知縣,但是當我在safari中查看它顯示南的所有數字,如果我設置日期在過去它不會觸發我的模型在else語句中。我已經在網絡上尋找解決方案,但沒有找到答案。倒計時計時器在Safari中不工作

$(document).ready(function() { 

     $('#popupTimer').delay(1000).fadeIn(600); 

     // Set the date we're counting down to (*** Set to Apr 9th after testing ***) 
     var countDownDate = new Date("Apr 3, 2017 24:00:00").getTime(); 

     // Update the count down every 1 second 
     var x = setInterval(function() { 

      // Get todays date and time 
      var now = new Date().getTime(); 

      // Find the distance between now an the count down date 
      var distance = countDownDate - now; 

      // Time calculations for days, hours, minutes and seconds 
      var days = Math.floor(distance/(1000 * 60 * 60 * 24)); 
      var hours = Math.floor((distance % (1000 * 60 * 60 * 24))/(1000 * 60 * 60)); 
      var minutes = Math.floor((distance % (1000 * 60 * 60))/(1000 * 60)); 
      var seconds = Math.floor((distance % (1000 * 60))/1000); 

      // Display the result in the element with id="display" 
      document.getElementById("display").innerHTML = days + " Days " + hours + " Hours " + minutes + " Minutes " + seconds + " Seconds "; 

      // If the count down is finished, 
      if (distance < 0) { 
       clearInterval(x); 
       document.getElementById("display").innerHTML = "EXPIRED"; 
       $('#myModal').modal('show'); 
       $(".myDIV").hide(); 
       $('#chooseProductThree').show(); 
       $(".panel-heading").addClass("active-panel"); 
      } 
     }, 1000); 
    }); 
+0

你做一個Windows設備的測試? – Konstantinos

+0

@Konstantinos Testes在Mac上完成 –

+0

也許Safari不明白新的日期getTime,所以用Date.parse @Cory改變它Kelly – Konstantinos

回答

0

我認爲Safari無法解析日期在這條線:

var countDownDate = new Date("Apr 3, 2017 24:00:00").getTime(); 

改成這樣:

var countDownDate = Date.parse("Apr 3, 2017 24:00:00");