gpt4 book ai didi

javascript - 没有周末和特定月份的日期选择器

转载 作者:行者123 更新时间:2023-12-03 05:05:46 26 4
gpt4 key购买 nike

我一直在尝试做一个没有周末和特定月份的日期选择器。我可以让其中一个工作,但在尝试让两者同时工作时遇到问题。有什么建议吗?
这是我的 fiddle ... https://jsfiddle.net/CreativeConcepts/39jtLhwm/

var RangeDates = ["4/1/2017, 6/30/2017", "11/1/2017, 12/31/2017", "4/1/2018, 6/30/2018", "11/1/2018, 12/31/2018", "4/1/2019, 6/30/2019", "11/1/2019, 12/31/2019",];
var RangeDatesIsDisable = true;
function DisableDays(date) {
var isd = RangeDatesIsDisable;
var rd = RangeDates;
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
for (i = 0; i < rd.length; i++) {
var ds = rd[i].split(',');
var di, df;
var d1, m1, y1, d2, m2, y2;

if (ds.length == 1) {
di = ds[0].split('/');
d1 = parseInt(di[1]);
m1 = parseInt(di[0]);
y1 = parseInt(di[2]);
if (y1 == y && m1 == (m + 1) && d1 == d) return [!isd];
} else if (ds.length > 1) {
di = ds[0].split('/');
df = ds[1].split('/');
d1 = parseInt(di[1]);
m1 = parseInt(di[0]);
y1 = parseInt(di[2]);
d2 = parseInt(df[1]);
m2 = parseInt(df[0]);
y2 = parseInt(df[2]);

if (y1 >= y || y <= y2) {
if ((m + 1) >= m1 && (m + 1) <= m2) {
if (m1 == m2) {
if (d >= d1 && d <= d2) return [!isd];
} else if (m1 == (m + 1)) {
if (d >= d1) return [!isd];
} else if (m2 == (m + 1)) {
if (d <= d2) return [!isd];
} else return [!isd];
}
}
}
}
return [isd];
}
$(document).ready(function() {
$("#datepicker").datepicker({
minDate: 0,
maxDate: null,
dateFormat: 'MM dd, yy',
beforeShowDay: DisableDays
});
});

最佳答案

查看星期几并返回将允许您执行此操作。

if(date.getDay() == "6" || date.getDay() == "0" ){ return isd } 

https://jsfiddle.net/39jtLhwm/3/

关于javascript - 没有周末和特定月份的日期选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42011050/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com