3

我正在尝试什么

我正在尝试实现一个事件管理站点,在该站点中,单击链接时会出现一个弹出窗口,其中包含显示事件的日历。我在这里使用jquery 周历

要求

我在这里面临的问题是,第一次单击链接时日历工作正常。但是,当我再次单击它而不刷新页面时,日历不会显示。当我检查它显示错误

TypeError: options.shortDays is undefined

...options.useShortDayNames ? options.shortDays[date.getDay()] : options.longDays[d...jquery.weekcalendar.js (line 3098).

我该如何解决这个问题?

日历仅在页面加载后第一次工作。

脚本

 <a href="#" data-reveal-id="reveal_popup" onclick="calendarpop('MT','1');" data-closeonbackgroundclick="false" data-dismissmodalclass="close-reveal-modal">due_today</a>

 <div id="reveal_popup" class="reveal-modal">
   <div id="calendar_popup"></div>
   <a class="close-reveal-modal">&#215;</a>
 </div>


 function calendarpop(cat,typ) {

    if(typ == 1){
        var days = 1;
    }
    else if(typ==2){
        var days = 2;
    }
    else if(typ==3){
        var days = 7;
    }

    var $calendar = $('#calendar_popup').weekCalendar({
        timeslotsPerHour: 4,
        scrollToHourMillis : 0,
        height: function($calendar){
            return $(window).height() - $('h1').outerHeight(true);
        },
        eventRender : function(calEvent, $event) {
            if (calEvent.end.getTime() < new Date().getTime()) {
                $event.css('backgroundColor', '#aaa');
                $event.find('.wc-time').css({
                    backgroundColor: '#999',
                    border:'1px solid #888'
                });
            }
        },

        data : function(start, end, callback) {
            $.getJSON(
            site_url()+'/event/eventpop/'+cat+'/'+typ,
            '',
            function(result) {
                callback(result);
            }
        );
        },
        allowCalEventOverlap : true,
        overlapEventsSeparate: true,
        showAsSeparateUser: false,
        displayOddEven: true,
        displayFreeBusys: true,
        daysToShow: days,
        buttons: false,
        headerSeparator: ' ',
        useShortDayNames: true,
        firstDayOfWeek: $.datepicker.firstDay,
        shortDays: $.datepicker.dayNamesShort,
        longDays: $.datepicker.dayNames,
        shortMonths: $.datepicker.monthNamesShort,
        longMonths: $.datepicker.monthNames,
        businessHours :{
            start: 6, 
            end: 22, 
            limitDisplay: true
        },
        dateFormat: 'd F Y'
    });

}
4

1 回答 1

0

你能去这里吗:http: //jsfiddle.net/83mmH/14/

请将 URL 添加到 JSON 数据中,然后我们可以从那里进行调试。

我还发现将所有 JS 外部化(包括从 html 中删除 onclick="" 并改为使用 jQuery 事件侦听器)更易于维护。

jQuery(document).ready(function($)
                       {
$('#reveal_popup').click(function()
{
  calendarpop('MT','1');
});
var calendarpop = function calendarpop(cat,typ) 
{
var days;
    if(typ == 1){
        days = 1;
    }
    else if(typ==2){
        days = 2;
    }
    else if(typ==3){
        days = 7;
    }

    var $calendar = $('#calendar_popup').weekCalendar({
        timeslotsPerHour: 4,
        scrollToHourMillis : 0,
        height: function($calendar){
            return $(window).height() - $('h1').outerHeight(true);
        },
        eventRender : function(calEvent, $event) {
            if (calEvent.end.getTime() < new Date().getTime()) {
                $event.css('backgroundColor', '#aaa');
                $event.find('.wc-time').css({
                    backgroundColor: '#999',
                    border:'1px solid #888'
                });
            }
        },

        data : function(start, end, callback) {
            $.getJSON(
            site_url()+'/event/eventpop/'+cat+'/'+typ,
            '',
            function(result) {
                callback(result);
            }
        );
        },
        allowCalEventOverlap : true,
        overlapEventsSeparate: true,
        showAsSeparateUser: false,
        displayOddEven: true,
        displayFreeBusys: true,
        daysToShow: days,
        buttons: false,
        headerSeparator: ' ',
        useShortDayNames: true,
        firstDayOfWeek: $.datepicker.firstDay,
        shortDays: $.datepicker.dayNamesShort,
        longDays: $.datepicker.dayNames,
        shortMonths: $.datepicker.monthNamesShort,
        longMonths: $.datepicker.monthNames,
        businessHours :{
            start: 6, 
            end: 22, 
            limitDisplay: true
        },
        dateFormat: 'd F Y'
    });
}
});
于 2013-05-19T17:48:07.137 回答