2016-06-08 25 views
0

我一直在致力於costum Javascript Countdown,它從localhost數據庫檢索start_dateend_date
日期計數由Google Chrome正常工作,但在Firefox和Opera中,它只表示NaNJavascript CountDown在Firefox上顯示NaN

這是我的jQuery與PHP。有人可以告訴我我的代碼有什麼問題嗎?

這是顯示了Firefox和Opera:當今年是YY格式

<?php 

    include("connect.php"); 
    $query="select * from account where Account_No='".$_SESSION['Account_No']."' "; 
    $rownum=mysql_query($query); 


    while($row = mysql_fetch_array($rownum)) 
    { 
    $End_Time=$row['End_Time']; 
    } 
    $End = strtotime($End_Time); 
    $Year = date("y",$End); 
    $Month = date("m",$End); 
    $Day = date("d",$End); 
    $Hour = date("H",$End); 
    $Minute = date("i",$End); 
    ?> 
    <script type="text/javascript" > 
    var current="License has expired!"; 
    var year= <?php echo $Year; ?>; 
    var month= <?php echo $Month; ?>; 
    var day= <?php echo $Day; ?>; 
    var hour= <?php echo $Hour; ?>; 
    var minute= <?php echo $Minute; ?>; 
    var tz=-5; 



    var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); 

    function countdown(yr,m,d,hr,min){ 
     theyear=yr;themonth=m;theday=d;thehour=hr;theminute=min; 
     var today=new Date(); 
     var todayy=today.getYear(); 
     if (todayy < 1000) { 
     todayy+=1900; } 
     var todaym=today.getMonth(); 
     var todayd=today.getDate(); 
     var todayh=today.getHours(); 
     var todaymin=today.getMinutes(); 
     var todaysec=today.getSeconds(); 
     var todaystring1=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec; 
     var todaystring=Date.parse(todaystring1)+(tz*1000*60*60); 
     var futurestring1=(montharray[m-1]+" "+d+", "+yr+" "+hr+":"+min); 
     var futurestring=Date.parse(futurestring1)-(today.getTimezoneOffset()*(1000*60)); 
     var dd=futurestring-todaystring; 
     var dday=Math.floor(dd/(60*60*1000*24)*1); 
     var dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1); 
     var dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1); 
     var dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1); 
     if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=0){ 
      document.getElementById('count2').innerHTML=current; 
      document.getElementById('count2').style.display="inline"; 
      document.getElementById('count2').style.width="390px"; 
      document.getElementById('dday').style.display="none"; 
      document.getElementById('dhour').style.display="none"; 
      document.getElementById('dmin').style.display="none"; 
      document.getElementById('dsec').style.display="none"; 
      document.getElementById('days').style.display="none"; 
      document.getElementById('hours').style.display="none"; 
      document.getElementById('minutes').style.display="none"; 
      document.getElementById('seconds').style.display="none"; 
      return; 
     } 
     else { 
      document.getElementById('count2').style.display="none"; 
      document.getElementById('dday').innerHTML=dday; 
      document.getElementById('dhour').innerHTML=dhour; 
      document.getElementById('dmin').innerHTML=dmin; 
      document.getElementById('dsec').innerHTML=dsec; 
      setTimeout("countdown(theyear,themonth,theday,thehour,theminute)",1000); 
     } 
    } 
    </script> 

<?php 
    echo "License will exprie after : <br> 
    <div id='forms'> 
     <div class='numbers' id='count2' style='position: absolute; top: 10px; height: 60px; padding: 15px 0 0 10px; background-color: #000000; z-index: 20;'></div> 
     <img src='images/bkgdimage.gif' class='background' style='position: absolute; left: 69px; top: 12px;'/> 
     <img src='images/line.jpg' class='line' style='position: absolute; left: 69px; top: 40px;'/> 
     <div class='numbers' id='dday' style='position: absolute; left: 69px; top: 21px;' ></div> 

     <img src='images/bkgdimage.gif' class='background' style='position: absolute; left: 141px; top: 12px;'/> 
     <img src='images/line.jpg' class='line' style='position: absolute; left: 141px; top: 40px;'/> 
     <div class='numbers' id='dhour' style='position: absolute; left: 141px; top: 21px;' ></div> 

     <img src='images/bkgdimage.gif' class='background' style='position: absolute; left: 213px; top: 12px;'/> 
     <img src='images/line.jpg' class='line' style='position: absolute; left: 213px; top: 40px;'/> 
     <div class='numbers' id='dmin' style='position: absolute; left: 213px; top: 21px;' ></div> 

     <img src='images/bkgdimage.gif' class='background' style='position: absolute; left: 285px; top: 12px;'/> 
     <img src='images/line.jpg' class='line' style='position: absolute; left: 285px; top: 40px;'/> 
     <div class='numbers' id='dsec' style='position: absolute; left: 285px; top: 21px;' ></div> 

     <div class='title' id='days' style='position: absolute; left: 66px; top: 73px;' >Days</div> 
     <div class='title' id='hours' style='position: absolute; left: 138px; top: 73px;' >Hours</div> 
     <div class='title' id='minutes' style='position: absolute; left: 210px; top: 73px;' >Minutes</div> 
     <div class='title' id='seconds' style='position: absolute; left: 282px; top: 73px;' >Seconds</div> 
    </div>"; 
?> 
+0

它缺少您需要縮小問題的圖像 –

+0

更換

$Year = date("y",$End); 

。 – jeroen

+0

是的,還請修復圖像。 –

回答

0

Firefox不解析日期。使用YYYY代替,所以在你的代碼,你應該用

$Year = date("Y",$End); 
+0

謝謝我的男人......它的工作。 :-) –