首页 > 解决方案 > 需要在日期选择器联系表 7 中禁用假期和日期

问题描述

我看到了许多解决方案,但无法在我的联系表格 7 上禁用周日周一和节假日。尝试使用此解决方案并将其 id 放置在函数和页脚文件中,但它仍然显示。代码是

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<script>
    jQuery("#datepicker").datepicker({
        beforeShowDay: function (date) {
            return [date.getDay() == 2 || date.getDay() == 3 || date.getDay() == 4 ||
            date.getDay() == 5 || date.getDay() == 6, ""]
        }
    });
</script>

<label> <span style="color: #000080;"><strong>Your Appointment Date</strong></span>(required)
[date* date-163 id:datepicker]</label>

标签: jquerywordpressuser-interfacejquery-uiplugins

解决方案


你可以用这个替换你的脚本 .. 并将你的假期列表附加到 removeDays 变量中。

function disabledays(date) {
    var ymd = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
        //if u have to disable a list of day
         var removeDays = ["2013-6-11","2013-6-31" ];
         if ($.inArray(ymd, removeDays) >= 0) {
        return [false];
    } else {
        //Show accept sundays
        var day = date.getDay();
        return [(day == 1 || day == 2 || day == 3 || day == 4 ||day == 5 ||day == 6 )];
    }
}

$(function () {
    $('#datepicker').datepicker({
        beforeShowDay: disabledays
    });
});

如果仍然无法正常工作,请分享您的控制台错误。


推荐阅读