我正在尝试在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文件中运行一个console.log来获取变量时,我得到[“2015-03-05”,“2015-03-06”,“2015-03-07”,“2015-03- 08“,”2015-03-08“]输出从数据库中读取,该输出是正确的,但这些日期在日期选择器中没有禁用。有人知道我哪里出错吗?
答案 0 :(得分:0)
而不是
<?php echo json_encode($date_list_res); ?>;
输入
<?php echo $date_list_res; ?>;
一切都应该是花花公子。