如何从mysql表的bootstrap datepicker中显示禁用日期?

时间:2018-07-27 15:23:50

标签: bootstrap-datepicker

任何人都知道如何将mysql表中的某些日期显示到bootstrap datepicker js代码中?还需要注意的是今天()日期。 任何帮助将不胜感激!

js代码:

<script type="text/javascript">
        var todayDate = new Date().getDate();
        var datepicker, config;
        config = {
           
            format: 'yyyy-mm-dd',
            uiLibrary: 'bootstrap4',
            disableDates: [<?php while ($off = $daysoff->fetch(PDO::FETCH_ASSOC)) { echo implode("'",$off['day'],"', ");} ?>],
            disableDaysOfWeek: [0],
            minDate: '<?php echo date(); ?>'
        };
        $(document).ready(function () {
            datepicker = $('#datepicker').datepicker(config);
            $('#ddlLanguage').on('change', function () {
                var newLang = $(this).val();
                config.locale = newLang;
                datepicker.destroy();
                datepicker = $('#datepicker').datepicker(config);
                disableDates: [new Date(2017,10,11), '20/07/2018'];
            });
        });
    </script>

和mysql查询:

select day from daysoff where status='Active'

1 个答案:

答案 0 :(得分:0)

解决了!

<?php while ($off = $daysoff->fetch(PDO::FETCH_ASSOC)) { $offs[] = $off['day']; $json_array = json_encode($offs);} ?>

    <script type="text/javascript">
         var arrayObjects = <?php echo $json_array; ?>;
        var todayDate = new Date().getDate();
        var datepicker, config;
        config = {
           
            format: 'yyyy-mm-dd',
            uiLibrary: 'bootstrap4',
            disableDates: arrayObjects,
            disableDaysOfWeek: [0],
            minDate: new Date(new Date().setDate(todayDate -1)),
            maxDate: new Date(new Date().setDate(todayDate +30))
        };
        $(document).ready(function () {
            datepicker = $('#datepicker').datepicker(config);
            $('#ddlLanguage').on('change', function () {
                var newLang = $(this).val();
                config.locale = newLang;
                datepicker.destroy();
                datepicker = $('#datepicker').datepicker(config);
            });
        });
    </script>