Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
每次加载页面时是否重置javascript倒计时?_Javascript_Countdown - Fatal编程技术网

每次加载页面时是否重置javascript倒计时?

每次加载页面时是否重置javascript倒计时?,javascript,countdown,Javascript,Countdown,我完全不知道这个javascript视图源代码: 下面是打开页面的php: 这是一个倒计时计时器,需要刷新后,每个页面加载 <?php function real_date_diff($date1, $date2 = NULL) { $diff = array(); if(!$date2) { $cd = getdate(); $date2 = $cd['year'].'-'.$cd['mon'].'-'.$cd['mday']

我完全不知道这个javascript视图源代码:

下面是打开页面的php:

这是一个倒计时计时器,需要刷新后,每个页面加载

    <?php
function real_date_diff($date1, $date2 = NULL)  
{
    $diff = array();

    if(!$date2) {
        $cd = getdate();
        $date2 = $cd['year'].'-'.$cd['mon'].'-'.$cd['mday'].' '.$cd['hours'].':'.$cd['minutes'].':'.$cd['seconds'];
    }

    $pattern = '/(\d+)-(\d+)-(\d+)(\s+(\d+):(\d+):(\d+))?/';
    preg_match($pattern, $date1, $matches);
    $d1 = array((int)$matches[1], (int)$matches[2], (int)$matches[3], (int)$matches[5], (int)$matches[6], (int)$matches[7]);
    preg_match($pattern, $date2, $matches);
    $d2 = array((int)$matches[1], (int)$matches[2], (int)$matches[3], (int)$matches[5], (int)$matches[6], (int)$matches[7]);

    for($i=0; $i<count($d2); $i++) {
        if($d2[$i]>$d1[$i]) break;
        if($d2[$i]<$d1[$i]) {
            $t = $d1;
            $d1 = $d2;
            $d2 = $t;
            break;
        }
    }

    $md1 = array(31, $d1[0]%4||(!($d1[0]%100)&&$d1[0]%400)?28:29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    $md2 = array(31, $d2[0]%4||(!($d2[0]%100)&&$d2[0]%400)?28:29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    $min_v = array(NULL, 1, 1, 0, 0, 0);
    $max_v = array(NULL, 12, $d2[1]==1?$md2[11]:$md2[$d2[1]-2], 23, 59, 59);
    for($i=5; $i>=0; $i--) {
        if($d2[$i]<$min_v[$i]) {
            $d2[$i-1]--;
            $d2[$i]=$max_v[$i];
        }
        $diff[$i] = $d2[$i]-$d1[$i];
        if($diff[$i]<0) {
            $d2[$i-1]--;
            $i==2 ? $diff[$i] += $md1[$d1[1]-1] : $diff[$i] += $max_v[$i]-$min_v[$i]+1;
        }
    }

    return $diff;
}
?>


I'm not sure what to edit in order to make the countdown not refresh on each page load. 

每次我加载页面时,倒计时插件的参数都是相同的,见下文-20天10秒。您必须计算事件发生前的天数/小时/分钟/秒,并将计算结果作为参数传递,以正确初始化倒计时。看起来这不是动态生成的-但是我无法通过查看源代码看到PHP代码,所以我不能确定您目前正在尝试做什么

            (function($){
            soundManager.setup({
                url: 'js/swf/',
                debugMode: false
            });
            $(window).load(function(){


                    $('#countdown').countdown({
                                                    timestamp   : { 'days'      : 20,
                                        'hours'     : 0,
                                        'minutes'   : 0,
                                        'seconds'   : 10                                            },
                        duration    : 360,

                        soundURL    : 'js/flip.mp3',
                        volume: 25,
                        callback    : function(days, hours, minutes, seconds){

                                var message = "";

                                message += days + " day" + ( days==1 ? '':'s' ) + ", ";
                                message += hours + " hour" + ( hours==1 ? '':'s' ) + ", ";
                                message += minutes + " minute" + ( minutes==1 ? '':'s' ) + " and ";
                                message += seconds + " second" + ( seconds==1 ? '':'s' ) + " <br />";

                                $('.callback').html(message);
                            }
                        })

                })
            })(jQuery)

首先,你的页面上的倒计时是用java脚本而不是PHP编写的。我已经编辑了你的问题,希望mods可以解决

您的java脚本正在直接设置倒计时的开始:

$('#countdown').countdown({
timestamp   : { 'days'      : 20,
'hours'     : 0,
'minutes'   : 0,
'seconds'   : 10    

...
..
.
您需要做的是将这些值与倒计时的日期进行比较!您可以通过以下方式实现此目的:

确定从现在到倒计时日期的差异 计算出倒计时的每个日期部分看看 将每个日期部分放入一个变量,并用相关变量替换上述代码示例中的位。
您不能使用view source查看PHP代码。您必须将代码粘贴到此处。您将时间设置为包含20:00:00:00的固定值。从机器上读取实时数据,计算剩余的显示时间。