duanjiong1952 2015-03-04 16:15
浏览 43
已采纳

禁用jQuery UI日期选择器日期

I am trying to disable dates in a jQuery UI Date Picker, it works when I hard code the dates in to the variable in the JS file as follows:

var bookedDays = ["2015-3-7","2015-3-8","2015-3-15"];

In my PHP file I have:

<?php
$testing = "SELECT fromdate, todate FROM messages WHERE listing_id = '".$_GET['listingid']."'";
        $resulttesting = mysql_query($testing) or die(mysql_error() . "<br>" . $testing);
        while ($rowtesting = mysql_fetch_assoc($resulttesting)) 
{
    $from = $rowtesting['fromdate'];
    $to = $rowtesting['todate'];

}

$start_time = strtotime($from);
$end_time = strtotime($to);
$date_list = array($from);

$current_time = $start_time;

while($current_time < $end_time) {
    //Add one day
    $current_time += 86400;
    $date_list[] = date('Y-m-d',$current_time);
}
//Finally add end date to list, array contains all dates in order
$date_list[] = $to;
$date_list_res = '["' . implode('","', $date_list) . '"]';

print_r ($date_list_res);

?>
<script type="text/javascript">
    var bookedDays = <?php echo json_encode($date_list_res); ?>;
</script>

When I run a console.log in the JS file for the variable bookedDays I get ["2015-03-05","2015-03-06","2015-03-07","2015-03-08","2015-03-08"] output which is read from the database which is correct but these dates are not disabling in the date picker. Does anybody know where I'm going wrong?

  • 写回答

1条回答 默认 最新

  • duanju9104 2015-03-04 16:46
    关注

    Instead of

    <?php echo json_encode($date_list_res); ?>;
    

    Type just

    <?php echo $date_list_res; ?>;
    

    Everything should be dandy.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突