我试图在jQuery UI日期选择器中禁用日期,当我将日期硬编码到JS文件中的变量中时,它可以工作,如下所示:
var bookedDays = ["2015-3-7","2015-3-8","2015-3-15"];
在我的PHP文件中,我有:
<?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>
当我在JS文件中为变量bookedDays运行console.log时,我得到了["2015-03-05"、"2015-03-06"、"201503-07"、"2015.03-08"、"2015 03-08"]输出,该输出是从数据库中读取的,是正确的,但这些日期没有在日期选择器中禁用。有人知道我哪里错了吗?
而不是
<?php echo json_encode($date_list_res); ?>;
只键入
<?php echo $date_list_res; ?>;
一切都应该是美好的。