我在我的网站上使用 Jquery datepicker,以便客户选择所需的交货日期。目前,我已将其设置为 minDate 4,不包括周末或节假日。我刚刚意识到我需要考虑一天中的时间,这样如果有人在下午 2 点之后下订单,它就不会在 minDate 中计算这一天(因为发货太晚了)。
我能够找到一些关于它的帖子,其中一个似乎特别适用:
但是,我很难将其应用于我当前的脚本(如下)。如果有人能告诉我如何适应它,那将是非常酷的。
非常感谢您的时间和帮助!~苏珊
<script type="text/javascript">
$(document).ready(function() {
//holidays
var natDays = [
[1, 1, 'uk'],
[12, 25, 'uk'],
[12, 26, 'uk']
];
var dateMin = new Date();
var weekDays = AddBusinessDays(4);
dateMin.setDate(dateMin.getDate() + weekDays);
function AddBusinessDays(weekDaysToAdd) {
var curdate = new Date();
var realDaysToAdd = 0;
while (weekDaysToAdd > 0){
curdate.setDate(curdate.getDate()+1);
realDaysToAdd++;
//check if current day is business day
if (noWeekendsOrHolidays(curdate)[0]) {
weekDaysToAdd--;
}
}
return realDaysToAdd;
}
function noWeekendsOrHolidays(date) {
var noWeekend = $.datepicker.noWeekends(date);
if (noWeekend[0]) {
return nationalDays(date);
} else {
return noWeekend;
}
}
function nationalDays(date) {
for (i = 0; i < natDays.length; i++) {
if (date.getMonth() == natDays[i][0] - 1 && date.getDate() == natDays[i][1]) {
return [false, natDays[i][2] + '_day'];
}
}
return [true, ''];
}
$('#datepicker').datepicker({
inline: true,
beforeShowDay: noWeekendsOrHolidays,
showOn: "both",
firstDay: 0,
dateformat: "dd/mm/yy",
changeFirstDay: false,
showButtonPanel: true,
minDate: dateMin
});
});
</script>
<p>
<label for="datepicker">Desired Delivery Date: </label>
<input class="input-medium" type="text" id="datepicker" placeholder="ex. 01/01/2013" name="properties[Delivery Date]" readonly />
<label><font size=1>Need it faster? Please call us! (800) 880-0307</font>
</label></p>
<style>
#datepicker { height: 20px; }
#datepicker {-webkit-border-radius: 0 3px 3px 0; -moz-border-radius: 0 3px 3px 0; border-radius: 0 3px 3px 0;}
</style>