【问题标题】:Disable Specific Dates in DatePicker Based on php Result根据 php 结果禁用 DatePicker 中的特定日期
【发布时间】:2021-02-24 10:25:04
【问题描述】:

我正在尝试使用 php 禁用基于 mysql 查询的已选择日期 我在 javascript 变量(var disabledDate)中得到了 php 结果。 这是我的代码:

    $(function () { 
      $('#school').change(function(){ // this is dropdown
          var dis_date;
            var id = $(this).val();
            var dis_date;
        $.ajax({
            type: "GET",
            url: "details.php",
            data: "pass_id="+id,
            success: success
        });
     function success(data) //data received here is ["2020/12/20","2020/12/19"]
    {   
        var disabledDate = data.trim();
        alert(disabledDate);
            jQuery(function() 
            {       
                var date = new Date();
                var currentMonth = date.getMonth();
                var currentDate = date.getDate();
                var currentYear = date.getFullYear();

            $('#calender').datepicker
            ({
                beforeShowDay:before,
                dateFormat: 'yy-mm-dd',
                minDate: new Date(currentYear, 11, 1),
                disabledDates: disabledDate,
                maxDate: new Date(currentYear, 12, 31)
            });
        });
         var before=   function(dt)
         {
            return [dt.getDay() === 0 || dt.getDay() === 6, ""];
         }
    }
     });
    });

无法禁用 datepicker 中的日期。任何帮助!!!

【问题讨论】:

    标签: javascript php jquery datepicker bootstrap-datepicker


    【解决方案1】:

    做这样的事情。

    将您从数据库中获取的日期放入这样的数组中。

    var array = ["2020/12/20","2020/12/19"]
    

    然后像这样编码。

    $('#calender').datepicker({
        beforeShowDay: function(date){
            var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
            return [ array.indexOf(string) == -1 ]
        }
    });
    

    查看演示here

    【讨论】:

    • 感谢您的回复。我试过这个我得到这个错误无法读取未定义的属性'formatDate'。(即使我尝试手动输入):(
    • 在之前的 ShowDay 中,我已经尝试只显示周末
    猜你喜欢
    • 2016-02-13
    • 2017-07-31
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    • 2010-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多