在今天的日期和设置日期之间的jquery日历中禁用日期,如果到达则在周末也是如此

时间:2013-06-11 06:10:08

标签: php jquery calendar

假设今天的日期是11-6-2013

$("#departure").datepicker({
            dateFormat: "dd/mm/yy",
            changeMonth: true,
            changeYear: true,
            maxDate: "+1y",
             minDate: +4,
        });
$("#departure").datepicker("setDate", "5");
<input id="departure" />

这里15和16是周末所以它不应该来,它应该跳过并且来到18-3-2013。 请帮我。 看这里:- 这一个是完美的: - enter image description here

但是截图15和16落在坐着和太阳上,所以它应该跳过,17和18应该来。

3 个答案:

答案 0 :(得分:0)

如果你想禁用周末,jquery ui有一个内置的功能。在datepicker init上添加beforeShowDay: $.datepicker.noWeekends。 ref:api.jqueryui.com/datepicker /

$("#departure").datepicker({
    beforeShowDay: $.datepicker.noWeekends,
    dateFormat: "dd/mm/yy",
    changeMonth: true,
    changeYear: true,
    maxDate: "+1y",
    minDate: +4
});

答案 1 :(得分:0)

要禁用您可以使用beforeShowDay和自定义功能处理的特定日期。

var unavailableDates = ["9-5-2011","14-5-2011","15-5-2011"];

function unavailable(date) {
  dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
  if ($.inArray(dmy, unavailableDates) < 0) {
    return [true,"","Custom message here"];
  } else {
    return [false,"","Custom message here"];
  }
}

$('#departure').datepicker({ beforeShowDay: unavailable });

要禁用周末,您可以使用beforeShowDay: $.datepicker.noWeekends @soderslatt在回答中提到。

现场演示here

答案 2 :(得分:0)

我得到了答案。

<html>
    <head>
        <title>Collection Date</title>

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> 
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js"></script> 
        <link type="text/css" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css" /> 

    </head>
<body>
<form name="Form1" method="post" action="TestDatePicker.asp" id="Form1">

<h2>Collection Form</h2>

<fieldset>
    <legend>Choose the collection date</legend>

    <div id="datepicker"></div>
    <input type="text" id="txtCollectionDate" name="txtCollectionDate" class="requiredField" style="display: none;" />

</fieldset>

<input type="submit" name="submit" value="Submit" />

</form>
<script type="text/javascript">
    $(document).ready(function() {

        var dateMin = new Date();
        //alert(dateMin);
        var weekDays = AddWeekDays(5);
        alert(weekDays);
        alert(weekDays);

        dateMin.setDate(dateMin.getDate() + weekDays);

        var natDays = [
          [1, 1, 'uk'],
          [12, 25, 'uk'],
          [12, 26, 'uk']
        ];

        function noWeekendsOrHolidays(date) {
            var noWeekend = $.datepicker.noWeekends(date);
            if (noWeekend[0]) {
                return nationalDays(date);
            } else {
                return noWeekend;
            }
        }
        function nationalDays(date) {
            for (i = 0; i < natDays.length; i++) {
                if (date.getMonth() == natDays[i][0] - 1 && date.getDate() == natDays[i][2]) {
                    return [false, natDays[i][2] + '_day'];
                }
            }
            return [true, ''];
        }
        function AddWeekDays(weekDaysToAdd) {
            var daysToAdd = 0
            var mydate = new Date()
            //alert(mydate);
            var day = mydate.getDay()
            //alert(day);
           // alert(weekDaysToAdd);
            weekDaysToAdd = weekDaysToAdd - (5 - day)
            if ((5 - day) < weekDaysToAdd || weekDaysToAdd == 1) {
                daysToAdd = (5 - day) + 2 + daysToAdd
            } else { // (5-day) >= weekDaysToAdd
                daysToAdd = (5 - day) + daysToAdd
            }
            while (weekDaysToAdd != 0) {
                var week = weekDaysToAdd - 5
                if (week > 0) {
                    daysToAdd = 7 + daysToAdd
                    weekDaysToAdd = weekDaysToAdd - 5
                } else { // week < 0
                    daysToAdd = (5 + week) + daysToAdd
                    weekDaysToAdd = weekDaysToAdd - (5 + week)
                }
            }

            return daysToAdd;
        }

        $('#datepicker').datepicker(
        {
            inline: true,
            beforeShowDay: noWeekendsOrHolidays,
            altField: '#txtCollectionDate',
            showOn: "both",
            dateFormat: "dd/mm/yy",

            changeFirstDay: false,
            minDate: dateMin
        });
    });
</script>


</body>
</html>

截图:

enter image description here

任何人都知道如何在这个国庆日播出