我正在“尝试”创建一个工作系统,该系统允许我的学生预订设备。我有两个日期输入,分别是借用日期和返回日期。目前,它是如何设置的,我有很多约会,并且周末禁用,而且学生无法在借阅当天归还齿轮。我正在尝试的下一步是仅向学生提供第二天的退货
例如,一个学生想在周末借用设备,但周一也是无学生日,因此返回日期仅需要是星期二。
maxDate:1 //没有考虑我从BeforeShowDay禁用的所有日期
我希望这是有道理的,这是我当前的混乱代码。
< script type = "text/javascript" >
jQuery(document).ready(function($) {
$(function() {
var publicd = ["4,3", "3,6", ];
var term1 = ["15,4", "16,4", "17,4", "18,4", "19,4", "22,4", "23,4", "24,4", "25,4", "26,4", ];
var term2 = ["7,7", "8,7", "9,7", "10,7", "11,7", "12,7", "15,7", "16,7", "17,7", "18,7", "19,7", ];
var term3 = ["29,9", "30,9", "1,10", "2,10", "3,10", "4,10", "7,10", "8,10", "9,10", "10,10", "11,10"];
var chrissy = ["2,12", "3,12", "4,12", "5,12", "6,12", "9,12", "10,12", "11,12", "12,12", "13,12", "16,12", "17,12", "18,12", "19,12", "20,12", "23,12", "24,12", "25,12", "26,12", "27,12", "30,12", "31,12", "1,1", "2,1", "3,1", "6,1", "7,1", "8,1", "9,1", "10,1", "13,1", "14,1", "15,1", "16,1", "17,1", "20,1", "21,1", "22,1", "23,1", "24,1", "27,1", "28,1", "29,1", "30,1", "31,1"];
var pupil = ["8,3", "22,7", "15,11", "9,4", "27,5"];
var combinedholidays = publicd.concat(term1, term2, term3, chrissy, pupil);
function TotalHolidays(date) {
var m = date.getMonth();
var d = date.getDate();
var currentdate = d + "," + (m + 1);
for (var i = 0; i < combinedholidays.length; i++) {
if ($.inArray(currentdate, combinedholidays) != -1) {
return [false];
}
}
var noWeekend = $.datepicker.noWeekends(date);
return !noWeekend[0] ? noWeekend : [true];
}
$("#field_borrow").datepicker({
dateFormat: 'yy/mm/dd',
minDate: new Date(),
beforeShowDay: TotalHolidays,
showOn: "button",
buttonImage: "https://jccamediaarts.edublogs.org/files/2018/06/if_calendar_285670-copy-2c5zvzr-2o5mcij-e1529025491810.png",
buttonImageOnly: true,
buttonText: "Select date",
onSelect: function(date) {
var selectedDate = new Date(date);
var msecsInADay = 86400000;
var endDate = new Date(selectedDate.getTime() + msecsInADay);
$("#field_return").datepicker("option", "minDate", endDate);
}
});
$("#field_return").datepicker({
dateFormat: 'yy/mm/dd',
beforeShowDay: TotalHolidays,
showOn: "button",
buttonImage: "https://jccamediaarts.edublogs.org/files/2018/06/if_calendar_285670-copy-2c5zvzr-2o5mcij-e1529025491810.png",
buttonImageOnly: true,
buttonText: "Select date"
});
}); <
/script>
答案 0 :(得分:0)
我看不到您显示的代码有任何具体问题。我已经对其进行了一些更新,它似乎可以按预期工作。
$(function() {
var publicd = ["4,3", "3,6"];
var term1 = ["15,4", "16,4", "17,4", "18,4", "19,4", "22,4", "23,4", "24,4", "25,4", "26,4", ];
var term2 = ["7,7", "8,7", "9,7", "10,7", "11,7", "12,7", "15,7", "16,7", "17,7", "18,7", "19,7", ];
var term3 = ["29,9", "30,9", "1,10", "2,10", "3,10", "4,10", "7,10", "8,10", "9,10", "10,10", "11,10"];
var chrissy = ["2,12", "3,12", "4,12", "5,12", "6,12", "9,12", "10,12", "11,12", "12,12", "13,12", "16,12", "17,12", "18,12", "19,12", "20,12", "23,12", "24,12", "25,12", "26,12", "27,12", "30,12", "31,12", "1,1", "2,1", "3,1", "6,1", "7,1", "8,1", "9,1", "10,1", "13,1", "14,1", "15,1", "16,1", "17,1", "20,1", "21,1", "22,1", "23,1", "24,1", "27,1", "28,1", "29,1", "30,1", "31,1"];
var pupil = ["8,3", "22,7", "15,11", "9,4", "27,5"];
var dtFt = 'yy/mm/dd';
var combinedHolidays = publicd.concat(term1, term2, term3, chrissy, pupil);
function isHoliday(day, holidays) {
var result = false;
if ($.inArray(day, holidays) >= 0) {
result = true;
};
return result;
}
function isWeekend(dt) {
var result = $.datepicker.noWeekends(dt);
return !result[0];
}
function TotalHolidays(date) {
var m = date.getMonth();
var d = date.getDate();
var currentDate = d + "," + (m + 1);
var result = [true, "weekDay"];
if (isHoliday(currentDate, combinedHolidays) || isWeekend(date)) {
result = [false, ""];
}
return result;
}
$("#borrow, #return").datepicker({
dateFormat: dtFt,
beforeShowDay: TotalHolidays,
showOn: "button",
buttonImage: "https://jccamediaarts.edublogs.org/files/2018/06/if_calendar_285670-copy-2c5zvzr-2o5mcij-e1529025491810.png",
buttonImageOnly: true,
buttonText: "Select date"
});
$("#borrow").datepicker("option", {
minDate: new Date(),
onSelect: function(date) {
var selectedDate = new Date(date);
var msecsInADay = 86400000;
var endDate = new Date(selectedDate.getTime() + msecsInADay);
$("#return").datepicker("option", "minDate", endDate);
}
});
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<p>Borrow Date: <input type="text" id="borrow" /></p>
<p>Return Date: <input type="text" id="return" /></p>
希望有帮助。