我正在使用Adam Shaw's Full Calender在我的预订页面上。
现在我想自定义此日历,使每个空单元格都应该有一个链接“地点预订”。单击此 anchor 应在新选项卡中将其打开,并获取 URL 中该单元格的日期。
这是我的代码
$('.fc-day-number').each(function() {
var day = parseInt($(this).html());
$(this).html('<a href="http://www.example.com/booking.php?booking_date='booking date of the cell'" target="_blank">' + day + '</a>');
});
目前我已将 anchor 放置在单元格的天数上。 但问题是,当我从插件的后退和前进按钮更改月份时, anchor 消失了,而且我无法获取单元格的日期。
我不是 JS 专家,任何帮助将不胜感激。
最佳答案
试试这个:
$('#calendar').fullCalendar({
viewRender: function(view, $element) {
$element.find('.fc-day-number').each(function() {
var $this = $(this);
var match = (/^(\d+)\-(\d+)\-(\d+)$/).exec($this.attr('data-date'));
var date = new Date(+match[1], +match[2], +match[3]);
$(this).wrapInner('<a href="http://www.example.com/booking.php?booking_date=' + encodeURIComponent(date.toUTCString()) + '" target="_blank"></a>');
});
}
});
<link href="http://fullcalendar.io/js/fullcalendar-2.7.2/fullcalendar.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
<script src="http://fullcalendar.io/js/fullcalendar-2.7.2/fullcalendar.min.js"></script>
<div id="calendar"></div>
关于javascript - 完整日历在空单元格中添加 anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37554136/