如何动态地将db值显示到datetime选择器中?

时间:2017-12-21 05:54:14

标签: javascript php jquery datetimepicker

我想动态地将我的db日期时间值动态显示到日历和时间输入字段中,但它已经静态工作。

这是我的脚本代码:

<script>
    var disabledDateTime = {'2017-12-14':[['2:30am','3:00am'],['6:30am','9:00am']],'2017-12-17':[['1:00am','3:00am'],['5:30am','2:00pm']]};
    $(function() {
        $('#pickTime').timepicker();
        $('#pickDate').datepicker({
            'format': 'yyyy-m-d',
            'autoclose': true
        }).on('changeDate',function(e){
            var ts = new Date(e.date);
            var m = ts.getMonth()+1;
            var dt = ts.getFullYear() + '-' + m + '-' + ts.getDate();
            var opt = {'disableTimeRanges': []}
            if(typeof(disabledDateTime[dt])!='undefined'){
                $('#pickTime').timepicker('setTime', '');
                opt = {'disableTimeRanges': disabledDateTime[dt]}
            }
            $('#pickTime').timepicker('option',opt);
        });
    });
</script>

这是我的HTML代码:

<input id="pickDate" type="text" class="date" />
<input id="pickTime" type="text" class="time" />

在这一行

var disabledDateTime = {'2017-7-14':[['2:30am','3:00am'],['6:30am','9:00am']],'2017-7-17':[['1:00am','3:00am'],['5:30am','2:00pm']]};

我添加了静态日期,但我希望使用php和我的php代码动态显示:

<?php
    $result = mysql_query("select * from dtpicker");

    $calc = [];
    while ($row = mysql_fetch_object($result))
    {
        $calc[] = [
            $row->date => [
                $row->starttime,
                $row->endtime
            ]
        ];
    }
?>
<script>
    var disabledDateTime = <?= json_encode($calc) ?>;
</script>

但是我无法动态显示,怎么做?

0 个答案:

没有答案