gpt4 book ai didi

jQuery Datepicker - 禁用周末/节假日和接下来的三个工作日

转载 作者:行者123 更新时间:2023-12-01 00:36:54 26 4
gpt4 key购买 nike

使用this rather neat approach我可以从日期选择器中禁用周末和节假日。

但是,我想将此与从今天起接下来的三个工作日的禁用结合起来。简单地设置最短日期相对容易:

var dateMin = new Date();
dateMin.setDate(dateMin.getDate() + 3);
$(function() {

$('#txtCollectionDate').datepicker(
{
beforeShowDay: noWeekendsOrHolidays,
showOn: "both",
dateFormat: "dd/mm/yy",
firstDay: 1,
changeFirstDay: false,
minDate: dateMin
});

});

但是,我真正需要一个计算工作日的函数:

var dateMin = new Date();
dateMin.setDate(AddBusinessDays(3));

任何能够转换的人 this到 JavaScript?

最佳答案

找到解决方案here .

代码(对 ASP 表示歉意):

<html>
<head>
<title>Collection Date</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js"></script>
<link type="text/css" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css" />

</head>
<body>

<h1>jQuery Datepicker Test</h1>

<%
If Request.Form("Submit") <> "" then
%>
<h2>Form Post Confirmation</h2>
<table border="1">
<tr>
<td><B>Form Variable</B></td>
<td><B>Value</B></td>
</tr>
<%
Dim Item
For Each Item In Request.Form
%>
<tr>
<td><%=Item %></td>
<td><%=Request.Form(Item) %></td>
</tr>
<% Next %>
</table>
<%
End If
%>

<form name="Form1" method="post" action="TestDatePicker.asp" id="Form1">

<h2>Collection Form</h2>

<fieldset>
<legend>Choose the collection date</legend>

<div id="datepicker"></div>
<input type="text" id="txtCollectionDate" name="txtCollectionDate" class="requiredField" style="display: none;" />

</fieldset>

<input type="submit" name="submit" value="Submit" />

</form>

<script type="text/javascript">
$(document).ready(function() {

var dateMin = new Date();
var weekDays = AddWeekDays(3);

dateMin.setDate(dateMin.getDate() + weekDays);

var natDays = [
[1, 1, 'uk'],
[12, 25, 'uk'],
[12, 26, 'uk']
];

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, ''];
}
function AddWeekDays(weekDaysToAdd) {
var daysToAdd = 0
var mydate = new Date()
var day = mydate.getDay()
weekDaysToAdd = weekDaysToAdd - (5 - day)
if ((5 - day) < weekDaysToAdd || weekDaysToAdd == 1) {
daysToAdd = (5 - day) + 2 + daysToAdd
} else { // (5-day) >= weekDaysToAdd
daysToAdd = (5 - day) + daysToAdd
}
while (weekDaysToAdd != 0) {
var week = weekDaysToAdd - 5
if (week > 0) {
daysToAdd = 7 + daysToAdd
weekDaysToAdd = weekDaysToAdd - 5
} else { // week < 0
daysToAdd = (5 + week) + daysToAdd
weekDaysToAdd = weekDaysToAdd - (5 + week)
}
}

return daysToAdd;
}

$('#datepicker').datepicker(
{
inline: true,
beforeShowDay: noWeekendsOrHolidays,
altField: '#txtCollectionDate',
showOn: "both",
dateFormat: "dd/mm/yy",
firstDay: 1,
changeFirstDay: false,
minDate: dateMin
});
});
</script>


</body>
</html>

关于jQuery Datepicker - 禁用周末/节假日和接下来的三个工作日,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2029626/

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