[英]enable previous dates of one week on date picker in jquery
i am trying to disable all the dates on datepicker
except dates 7days before from current date but it disables all the dates. 我试图禁用除当前日期前7天以外的日期
datepicker
上的所有日期,但它禁用所有日期。 it works fine when i un-comment the commented code lines and comment the else part "return true" line. 当我取消注释已注释的代码行并注释else部分“返回真实”行时,它工作正常。 but it disables the weekends too.
但它也禁用了周末。 so how can i achieve it without using
noweekends(currentdate)
所以我如何不使用
noweekends(currentdate)
实现它
$(document).ready(function () {
$(function () {
{
var currentDate = new Date();
$("#StartDate").datepicker({ beforeShowDay: DisableSpecificDates });
$("#StartDate").datepicker({ dateFormat: 'yy-mm-dd' }).val();
$("#StartDate").datepicker("setDate", currentDate);
}
});
$(function () {
{
var currentDate = new Date();
$("#StartDte").datepicker({ beforeShowDay:DisableSpecificDates });
$("#StartDte").datepicker("setDate", currentDate);
}
});
function DisableSpecificDates(currentdate) {
//var weekenddate = $.datepicker.noWeekends(currentdate);
var difference;
var minDate = new Date();
var todaydate = new Date();
var d = todaydate.getDate();
var prevdays = 0;
difference = d - 6;
if (d <= prevdays && d > 0) {
minDate.setDate(difference);
}
else {
minDate.setDate(difference);
}
var datemin =new Date (minDate);
var day = todaydate.getDay();
switch (day)
{
case 0:
case 1:
prevdays = 4;
break;
case 2:
case 3:
case 4:
case 5:
prevdays = 2;
break;
case 6:
prevdays = 3;
break;
}
datemin.setDate(datemin.getDate()+1);
var dateOfMin = (minDate.getDate()) - prevdays - 1;
minDate.setDate(dateOfMin);
if (currentdate > todaydate || currentdate < minDate)
{
return false;
}
return true;
//return weekenddate;
}
Seems like you want to set date range as example below , so below will fix date range and also disable weekends 好像您想像下面的示例一样设置日期范围,因此下面将修复日期范围并禁用周末
$( "#datepicker" ).
datepicker({ minDate: -20, maxDate: "+1M +10D", beforeShowDay: $.datepicker.noWeekends });
check datepicker : Date Range 检查datepicker:日期范围
or try like this 或尝试这样
$('#date-time-picker').datepicker({
format: 'YYYY-MM-DD',
useCurrent: false,
showClose: true,
minDate: '2018-03-09',
maxDate: '2018-03-15',
beforeShowDay: $.datepicker.noWeekends
})
but here you need to give mindate and max date from script , for simplicity i hardcoded date 但是在这里,您需要给出脚本的提示和最大日期,为简单起见,我将日期硬编码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.