gpt4 book ai didi

jQuery UI 日期选择器 maxdate

转载 作者:行者123 更新时间:2023-12-01 04:24:49 25 4
gpt4 key购买 nike

我需要让我的 jQueryUI 日期选择器的 maxDate 根据日期动态更新。现在,正如您将在下面看到的,有一个功能用于禁用周一至周四,因为我们的团队只能在周五至周日报告问题。所以我需要做的是让团队可以在周末继续报告,但下周末直到周四才可以报告。例如,今天是星期一,团队仍然可以报告上周四至周日的问题,并且在周四之前无法选择下周末的日期。这可能吗?

这是我到目前为止的代码:

  var fullDate = new Date();
var twoDigitMonth = ((fullDate.getMonth().length+1) === 1)? (fullDate.getMonth()+1) : '0' + (fullDate.getMonth()+1);

$('#startdate').datepicker({
maxDate: twoDigitMonth + "/" + fullDate.getDate() + "/" + fullDate.getFullYear(),
beforeShowDay: disableSpecificWeekDays
});


function disableSpecificWeekDays(date) {
if((date.getDay()==0) || (date.getDay() == 5) || (date.getDay() == 6) ){
return [true];
}else{
return [false];
}
}

最佳答案

这样的东西应该适合你:

function getMaxDate() {
// Maximum date is today by default.
var maxDate = new Date();

// Is today Thursday or greater (Thurs. - Sat.)
if (maxDate.getDay() >= 4) {
// Yes? Make the date today's date plus the difference between today and
// next Sunday
maxDate.setDate(
maxDate.getDate() + (7 - maxDate.getDay()));
}
return maxDate;
}

$('#startdate').datepicker({
maxDate: getMaxDate(),
beforeShowDay: disableSpecificWeekDays
});

示例: http://jsfiddle.net/RxQB4/

基本上,编写一个封装逻辑的函数。初始化日期选择器时,调用该函数来检索最大日期。

关于jQuery UI 日期选择器 maxdate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7395771/

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