简体   繁体   English

日期选择器-禁用将来的日期范围

[英]Date Picker - disabling a range of dates in the future

I have been trying to implement some additional code to disable a range of dates in the future on my date range picker, from my research I believe I need to use beforeShowDay , have the dates in an array and return a false if the dates are in the array but each time I try to spanner in some code it breaks the pickers. 我一直在尝试实现一些其他代码,以便将来在日期范围选择器上禁用日期范围,根据我的研究,我认为我需要使用beforeShowDay ,将日期放在array ,如果日期在该array但每次我尝试spanner在一些代码它打破了采摘。 I have to confess I don't know Javascript very well at all and only use it with plugins when I have to, any help would be gratefully received. 我不得不承认,我一点也不了解Javascript,并且只在需要时才将其与插件一起使用,我们将不胜感激地获得任何帮助。

var dateToday = new Date();
var dates = $("#from, #to").datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
minDate: dateToday,
onSelect: function(selectedDate) {
    var option = this.id == "from" ? "minDate" : "maxDate",
        instance = $(this).data("datepicker"),
        date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
    dates.not(this).datepicker("option", option, date);
}
});

I would like to disable from the 2nd of December 2017 to the January 27th 2018 我想从2nd of December 2017January 27th 2018停用

 $('#datePick').datepicker({ defaultDate: "+1w", changeMonth: true, numberOfMonths: 1, minDate: new Date(), beforeShowDay: function(date){ var val = new Date("2017-12-02") >= date || new Date("2018-01-28") < date ; return [ val ] } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script> <link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/redmond/jquery-ui.css" rel="stylesheet"/> // disabled 2nd of December 2017 to January 27th 2018<br> <input id='datePick'> 

use beforeShowDay and check which date you need to show. 使用beforeShowDay并检查您需要显示的日期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM