如何在jQueryUiDatepicker中使用BeforeShowDay禁用特定的日期和日期? [英] How To Disable Specific Days and Dates Using BeforeShowDay In jQueryUiDatepicker?
问题描述
我已经在jQueryUiDatepicker中具有正常运行的代码,该代码可以禁用星期五和星期六以及之前的所有日期(加上2天)。我的问题是尝试向此现有的Datepicker代码添加2个特定日期,这也会禁用这些日期。
I already have functioning code in jQueryUiDatepicker that disables Fridays and Saturdays and all previous days (plus 2 days). My issue is trying to add 2 specific dates to this existing Datepicker code that will also disable these dates.
这是我在jQueryUiDatepicker的第92行开始的现有代码:
This is my existing code on starting line 92 in jQueryUiDatepicker:
beforeShowDay: function(date) {
var show = true;
if(date.getDay()==5||date.getDay()==6) show=false
return [show];
},
beforeShow: function(){
var dateTime = new Date();
var hour = dateTime.getHours();
//If Hour is greater or equals to 8AM
if(hour >= 08){
//Disable all past days including tomorrow and today
$(this).datepicker( "option", "minDate", "+2" );
}
},
我正尝试停用2017年10月18日至19日,但失败了,这是我直接在上面的代码下面添加的代码:
I am trying to disable 18th and 19th October 2017 and failing, this is the code I have added directly underneath the above code:
beforeShowDay: var array = ['18/10/2017', '19/10/2017']
$('input').datepicker({
beforeShowDay: function(date){
var string = jQuery.datepicker.formatDate('dd/mm/yy', date);
return [ array.indexOf(string) == -1 ]
},
我的问题是如何禁用所有以前的日期,所有星期五和星期六以及十月的这两个日期?
My question is how can I disable all previous dates, all Fridays and Saturdays and these 2 dates in the October?
推荐答案
希望这会有所帮助
使用 inArray 代替 indexOf
,您还可以使用 minDate
use inArray instead of indexOf
and you can also disable all previous dates using minDate
var array = ["18/10/2017", "19/10/2017"];
$(function() {
$('input').datepicker({
minDate: new Date(),
beforeShowDay: function (date) {
$thisDate = date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear();
var day = date.getDay();
if ($.inArray($thisDate, array) == -1&&day!=5&&day!=6) {
return [true, ""];
} else {
return [false, "", "Unavailable"];
}
}
});
});
这篇关于如何在jQueryUiDatepicker中使用BeforeShowDay禁用特定的日期和日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!