0

我有一个活动日历,需要在活动日添加链接,我正在使用日期选择器 jQuery UI。

有谁知道获取当天索引的方法?

我的代码:

$.ajax({
            url: "includes/ajax/datepicker_events.php",
            data: "action=showdates",
            dataType: "json",
            success: function(calendarEvents){
                $("#datepicker").datepicker({
                    numberOfMonths: [1, 1],
                    showCurrentAtPos: 0,
                    beforeShowDay: function (date){
                        for (i = 0; i < calendarEvents.length; i++) {
                            if (date.getMonth() == calendarEvents[i][0] - 1
                              && date.getDate() == calendarEvents[i][1]
                              && date.getFullYear() == calendarEvents[i][2]) {

                              return [false,"ui-state-active",calendarEvents[i][3]];
                              }
                        }
                        return [true, ""];
                    }
                });
            }
        });
4

1 回答 1

2

选择这些日期时,我将使用OnSelect打开新链接。

JSFiddle

var calendarEvents = [[10,22,2013],[10,24,2013]];
var calendarHref = ["https://stackoverflow.com","https://google.com"];

$("#datepicker1").datepicker({
    numberOfMonths: [1, 1],
    showCurrentAtPos: 0,
    beforeShowDay: function (date) {
        for (i = 0; i < calendarEvents.length; i++) {
            if (date.getMonth() == calendarEvents[i][0] - 1 && date.getDate() == calendarEvents[i][1] && date.getFullYear() == calendarEvents[i][2]) {

                return [true, "ui-state-active", calendarEvents[i][3]];
            }
        }
        return [true, ""];
    },
    onSelect: function(dateText, inst) {
        for (i = 0; i < calendarEvents.length; i++) {
            if (inst.selectedMonth == calendarEvents[i][0] - 1 && inst.selectedDay == (""+ calendarEvents[i][1]) && inst.selectedYear == calendarEvents[i][2]) {
                window.open(
                  calendarHref[i],
                  '_blank'
                );
            }
        }
    }
});
于 2013-10-21T16:33:30.317 回答