1

我正在尝试将 javascript 文件作为 jquery ui datepicker 的插件来处理。基本上我有一个代表假期预订的数据库表,我可以从日期选择器日历中选择日期。我正在尝试禁用选择已在预订中预订的任何日期。这是我的 javascript 文件:

$(document).ready(function () {

$("#checkin").datepicker({
    changeMonth: true,
    changeYear: true,
    showOtherMonths: true,
    selectOtherMonths: true,
    dateFormat: 'DD, d MM, yy',
    altField: '#date_in',
    altFormat: 'yy-mm-dd',
    beforeShowDay: markInvalidDates,
    onChangeMonthYear: fetchFreeDays,
    firstDay: 1 // rows starts on Monday
});

$("#checkout").datepicker({
    changeMonth: true,
    changeYear: true,
    showOtherMonths: true,
    selectOtherMonths: true,
    dateFormat: 'DD, d MM, yy',
    altField: '#date_out',
    altFormat: 'yy-mm-dd',
    beforeShowDay: highlightDays,
    onChangeMonthYear: fetchFreeDays,
    firstDay: 1 // rows starts on Monday
});

});

var invalidDays = [];

function getReservations() {
$.ajax({
type: "POST",
url: "MullinsBayServices.asmx/GetVerifiedReservations",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: "false",
success: function(response) {
    var unvailableDates = response.d;
    $.each(unvailableDates, function(index, date) {
        invalidDays.push(date);
    });
},
failure: function(msg) {
    $('#output').text(msg);
}

});

function markInvalidDates(date) {
getReservations();
dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
if ($.inArray(dmy, invalidDays) == -1) {
    return [true, ""];
} else {
    return [false,"","Unavailable"];
}

}

我对 javascript/jquery 还是很陌生,不知道我在哪里出错了。假设 web 服务返回以 JSON 格式正确序列化的日期,这是否适合我想要完成的任务?

4

0 回答 0