jQuery变量里面的PHP变量不起作用

时间:2014-08-14 14:54:25

标签: php jquery

我有一个jquery var endDate,它存储倒计时的日期。

var endDate = "August 14, 2014 20:30:00";

倒计时工作正常。

当我向其添加php变量时,倒计时日期设置为00 00 00 NaN

$rebuyDayCountdown = date('F d, Y H:i:s',strtotime($resultRBD['rebuyDay']));
// outputs -> August 14, 2014 20:30:00

var endDate = "<?php echo $rebuyDayCountdown; ?>";

有什么问题?它与双引号有关吗?

编辑:提供更多代码。

注意:我的jquery在链接到php文件的另一个文件中

$sqlRBD = " SELECT gameTime, DATE_ADD(gameTime,INTERVAL 1 DAY) AS rebuyDay FROM ( ";
$sqlRBD .= "    SELECT * FROM schedule WHERE weekNumber = " . $week . " ORDER BY gameTime DESC ";
$sqlRBD .= ") x GROUP BY weekNumber ";

$queryRBD = mysql_query($sqlRBD);

while ($resultRBD = mysql_fetch_array($queryRBD)) {

    $rebuyDay = $resultRBD['rebuyDay'];
    $rebuyDayCountdown = date('F d, Y H:i:s',strtotime($resultRBD['rebuyDay']));
}

我已经回复了$ rebuayDay(2014-08-14 20:30:00)和$ rebuyDayCountdown(2014年8月14日20:30:00)的罚款。

下面的jquery代码

第一组代码工作正常。

//countdown for rebuy button
$(function() {

    // set the date to countdown too
    var endDate = "August 14, 2014 20:30:00";

    $('#rebuy-countdown').countdown({

        date: endDate,

        render: function(data) {

            $(this.el).html("<li class='counter-numbers'>" + this.leadingZeros(data.days, 2) + " <span class='counter-label'>days</span></li><li class='counter-numbers'>" + this.leadingZeros(data.hours, 2) + " <span class='counter-label'>hours</span></li><li class='counter-numbers'>" + this.leadingZeros(data.min, 2) + " <span class='counter-label'>minutes</span></li><li class='counter-numbers'>" + this.leadingZeros(data.sec, 2) + " <span class='counter-label'>seconds</span></li>");

        }
    });
});

此设置不起作用,并将日期设置为00 00 00 Nan

//countdown for rebuy button
$(function() {

    // set the date to countdown too
    var endDate = "<?php echo $rebuyDayCountdown; ?>";

    $('#rebuy-countdown').countdown({

        date: endDate,

        render: function(data) {

            $(this.el).html("<li class='counter-numbers'>" + this.leadingZeros(data.days, 2) + " <span class='counter-label'>days</span></li><li class='counter-numbers'>" + this.leadingZeros(data.hours, 2) + " <span class='counter-label'>hours</span></li><li class='counter-numbers'>" + this.leadingZeros(data.min, 2) + " <span class='counter-label'>minutes</span></li><li class='counter-numbers'>" + this.leadingZeros(data.sec, 2) + " <span class='counter-label'>seconds</span></li>");

        }
    });
});

1 个答案:

答案 0 :(得分:0)

为什么不创建Date类型的javascript变量? 您可以使用以下方式执行此操作:

var endDate = new Date('<?php echo $rebuyDayCountdown; ?>');