【发布时间】:2013-11-19 16:43:29
【问题描述】:
我目前正在使用 CLNDR 插件:http://kylestetz.github.io/CLNDR/ 一个很棒的小 jQuery 插件,用于生成日历。理想情况下,我希望将日历用作事件日历,即,如果您将事件添加到特定日期,它会将相关信息添加到该日期块。
我目前有这个 jsFiddle 演示:http://jsfiddle.net/neal_fletcher/32EEF/
默认情况下,数组中的事件使用不同的背景颜色设置样式。理想情况下,我想在包含事件的.day div 中添加一个 div,包含事件标题、信息等。没什么太花哨的,只是改变背景颜色。这是可能吗?任何建议将不胜感激!
jQuery:
$(document).ready( function() {
// here's some magic to make sure the dates are happening this month.
var thisMonth = moment().format('YYYY-MM');
// Here's our events array. We could grab this via AJAX as well.
var eventArray = [
{ date: thisMonth + "-24 07:52", title: "This is an event title", url: "http://google.com", time: "7:15PM" },
{ date: thisMonth + "-28", title: "the 28th, Part 1", url: "http://www.google.com" },
{ date: thisMonth + "-28", title: "the 28th, Part 2", arbitraryObject: 42 },
{ date: thisMonth + "-16", title: "Another title", anotherObject: "clndr exposes whatever is in your event object" }
];
var clndr2 = $('.cal2').clndr({
template: $('#template-calendar').html(),
events: eventArray,
startWithMonth: moment().add('month', 0),
clickEvents: {
click: function(target) {
console.log(target);
}
}
});
// bind both clndrs to the left and right arrow keys
$(document).keydown( function(e) {
if(e.keyCode == 37) {
// left arrow
clndr1.back();
clndr2.back();
}
if(e.keyCode == 39) {
// right arrow
clndr1.forward();
clndr2.forward();
}
});
});
HTML:
<div class="container">
<h3></h3>
<div class="cal2">
<script type="text/template" id="template-calendar">
<div class="clndr-controls">
<div class="clndr-previous-button">‹</div>
<div class="month"><%= month %></div>
<div class="clndr-next-button">›</div>
</div>
<div class="clndr-grid">
<div class="days-of-the-week">
<% _.each(daysOfTheWeek, function(day) { %>
<div class="header-day"><%= day %></div>
<% }); %>
<div class="days">
<% _.each(days, function(day) { %>
<div class="<%= day.classes %>" id="<%= day.id %>"><%= day.day %></div>
<% }); %>
</div>
</div>
</div>
</script>
</div>
</div>
【问题讨论】:
标签: javascript jquery html css calendar