我正在编写一个自定义日历,它由两部分组成,一个 div 显示月份网格,另一个 div 显示所选日期的事件。当前月份的日历网格会自动加载,并且每日事件的显示工作正常。但是,当用户单击按钮查看下个月或上个月时,单击日期不再有效。此外,更改月份不再适用于动态加载的日历。
这是我正在使用的 jQuery 代码:
<script type="text/javascript">
$(document).ready(
function() {
$('div.calendar_events').text('To view the events on any of the highlighted dates, simply click the date.');
$('div.number').click(
function(e) {
e.preventDefault();
var theDate = $(this).attr('id').split('-');
$('div.calendar_events').load('ajax/calendar_events.php?month=' + theDate[1] + '&day=' + theDate[2] + '&year=' + theDate[3]);
});
$('a.changemonth').click(
function(e) {
e.preventDefault();
var theDate = $(this).attr('id').split('-');
$('div.calendar').load('ajax/calendar_view.php?month=' + theDate[1] + '&year=' + theDate[2]);
});
});
</script>