【问题标题】:How to display disable dates in bootstrap datepicker from mysql table?如何在 mysql 表的引导日期选择器中显示禁用日期?
【发布时间】:2018-07-28 00:51:01
【问题描述】:

任何人都知道如何将 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'

【问题讨论】:

    标签: bootstrap-datepicker


    【解决方案1】:

    解决了!

    <?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>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多