gpt4 book ai didi

javascript - 如何使用 jQuery datepicker 禁用每个月的最后 3 天

转载 作者:行者123 更新时间:2023-12-01 15:39:49 26 4
gpt4 key购买 nike

$('.scheduledate').change(function() {
selectedDate = $(this).datepicker('getDate');
})

function checkDate(selectedDate) {
var today = new Date();
var d = selectedDate.getDate();
var dd = today.getDate();
if(d == dd || d == dd+1 || d == dd+1 || d == dd+1 || d==29 || d== 30 || d==31){
return [false,'na_dates','Close date F'];
}else{
return [true,' ','Open date T'];
}
}

最佳答案

这是 AlwaysHelpings 答案的副本,但采用了不同的方法来禁用一个月的最后三天。

var dateToday = new Date(); 

$("#datepicker").datepicker({
beforeShowDay: noLastThreeDays,
minDate: dateToday
});

function noLastThreeDays(date){
//REM: Last day of month
var tLastDayOfMonth = new Date(date.getFullYear(), date.getMonth() + 1, 0);

//REM: Date of the passed date
var tDate = date.getDate();

//REM: Lock the last three days of the month
if(
tDate === tLastDayOfMonth.getDate() ||
tDate === tLastDayOfMonth.getDate()-1 ||
tDate === tLastDayOfMonth.getDate()-2
){
return [false, "closed", "Sorry We are closed"]
}
else{
return [true, "", ""]
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/themes/smoothness/jquery-ui.css" />

<input type="text" id="datepicker" placeholder="Last three days disabled">

关于javascript - 如何使用 jQuery datepicker 禁用每个月的最后 3 天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62588659/

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