动态倒数计时器不工作时钟没有正确显示时间

时间:2016-06-22 21:59:28

标签: javascript php jquery timer

首先我有一个javascript flipclock,当我刷新它从头开始的页面时,因为我希望它从页面刷新之前停止的地方恢复,我希望我的计时器每天都停在4:上午00点或下午4点但是当我试图输入一些php时钟没有正确显示我不知道有没有任何PHP小提琴可用所以我可以显示什么是像jquery小提琴的芽

以下是我试图这样做的事情

    $query      = mysqli_query($connection, "SELECT * FROM timer WHERE id = '1'");
    $timer      = mysqli_fetch_array($query);
    $time_st    = $timer[2];
    $time_end   = $timer[3];
    $date       = $timer[1];
    $time_rem   = $date . " " . $time_st;
    $rem        = strtotime("$time_rem") - time();
    $today      = getdate();
    $time_end   = $today['hours'] . ':' . $today['minutes'] . ':' . $today['seconds'];
?>

我的时钟

<div class="clock_area">
            <div class="clock"></div>
            <p>COUNTDOWN TILL 4:20</p>
        </div>

<script type="text/javascript">

    $(document).ready(function() {
        var clock;

        clock = $('.clock').FlipClock({
            clockFace: 'HourlyCounter',
            autoStart: false,
            callbacks: {
                stop: function() {
                    $('.message').html('Offer Closed')
                }
            }
        });
         <?php 
          if($time_end == $time_st || $time_end == '04:20:00') { 
              ?>        
                   clock.setTime(0);
        <?php } else { ?>
        clock.setTime(<?php echo $rem; ?>);
          <?php } ?>
        clock.setCountdown(true);
        clock.start();
    });
</script>

请帮我解决这个问题,就像我的情景非常简单但有点合乎逻辑

1 个答案:

答案 0 :(得分:0)

你不能这样做

<?php 
          if($time_end == $time_st || $time_end == '04:20:00') { 
              ?>        
                   clock.setTime(0);
        <?php } else { ?>
        clock.setTime(<?php echo $rem; ?>);
          <?php } ?>

你应该这样做

<scritp>
...YOUR JS CODE...
<?php
if($time_end == $time_st || $time_end == '04:20:00') {
      echo "clock.setTime(0);";
}
else{
    echo "clock.setTime(".$rem.");";
}
?>

clock.setCountdown(true);
clock.start();
});
</script>