2

假设今天的日期是 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 是周末,所以它不应该来,它应该被跳过,并在 2013 年 3 月 18 日到来。请帮我。见这里:-这里这个工作完美:- 在此处输入图像描述

但在屏幕截图中,15 和 16 落在 sat 和 sun 上,所以应该跳过,而 17 和 18 应该来。

4

3 回答 3

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 在回答中提及。

现场演示在这里

于 2013-06-11T06:36:37.900 回答
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>

截屏:

在此处输入图像描述

谁知道这个国庆节怎么过

于 2013-06-12T04:40:18.080 回答
0

如果你想禁用周末,jquery ui 有一个内置功能。添加beforeShowDay: $.datepicker.noWeekends日期选择器初始化。参考:api.jqueryui.com/datepicker/

$("#departure").datepicker({
    beforeShowDay: $.datepicker.noWeekends,
    dateFormat: "dd/mm/yy",
    changeMonth: true,
    changeYear: true,
    maxDate: "+1y",
    minDate: +4
});
于 2013-06-11T06:16:04.020 回答