3

我正在使用此日历创建活动日历。我每个月都有一些常规活动,例如会议、派对、提交、研讨会。我的想法是如何根据活动名称更改日期的背景图像以及如何添加消息剩余日期不是动态事件。这是我的代码:

<!DOCTYPE html>
  <html>
  <head>
    <title>My Page</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
    <link rel="stylesheet" href="jw-jqm-cal.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
    <script type="text/javascript" src="jw-jqm-cal.js"></script>
    <script type="text/javascript">
        $(document).on('pageinit', "#view-calendar", function(event, ui) {
            var date = new Date();
            var d = date.getDate();
            var m = date.getMonth();
            var y = date.getFullYear();
            $("#calendar").jqmCalendar({

                events: [{
                    "summary": "Birthday Dinnaer",
                    "begin": new Date(y, m, d + 10),
                    "end": new Date(y, m, d + 11)
                }, {
                    "summary": "Meeting With Project Manager at Diamond Hall",
                    "begin": new Date(y, m, d + 3),
                    "end": new Date(y, m, d + 4)
                },

                ],
                months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
                days: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
                startOfWeek: 0
            });

            $("#calendar").bind('change', function(event, date) {
                console.log(date);
                //$("#message").empty();
                ///$("#message").append('<p><strong>There is No event at'+date+'</strong></p>');
            });
        })
    </script>
  </head>

  <body>
    <div data-role="page" id="view-calendar">
        <div data-role="header">
             <h1>Tradition Calendar</h1>

        </div>
        <div data-role="content">
            <div id="calendar"></div>
            <div id="message"></div>
        </div>
    </div>
  </body>
</html>
4

1 回答 1

3

我做了一个小修复,它将根据事件添加自定义类。它需要对jqm 日历库做一些小的改动。

我首先制作了三个自定义背景 CSS 类.wedding.meeting并且.party. 然后在您调用的代码中添加一个值.jqmCalender()

下载工作示例

$("#calendar").jqmCalendar({
  events: [{
      "summary": "Birthday Dinnaer",
        "begin": new Date(y, m, d + 10),
        "end": new Date(y, m, d + 11),
        "bg": "wedding" // or meeting or party "matches class name"
  }]

jqm calendar.js中,我做了以下更改

// line 11
bg: "bg",

// line 119 - to retrieve the value from .jqmCalendar() function
var bg = event[plugin.settings.bg];

在这里,日期获取样式,但我必须删除.importance以免覆盖自定义类。

// line 127
$a.append("<span>&bull;</span>").removeClass("importance-" + importance.toString()).addClass(bg);

在这里,当您单击日期时,它会将相同的样式添加到摘要中。

// line 211
$("<li class=" + bg + ">" + ((timeString != "00:00-00:00") ? timeString : "") + " " + summary + "</li>").appendTo($listview);

这是自定义类。

.wedding {
  background: #fcecfc;
}

.meeting {
  background: #f8ffe8;
}

.party {
  background: #ff3019;
}
于 2013-09-13T16:16:13.310 回答