javascript - 完整日历在空单元格中添加 anchor

标签 javascript jquery arrays fullcalendar fullcalendar-scheduler

我正在使用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/

相关文章:

javascript - 替换对象和数组中的元素?

javascript - Emscripten - 如何为采用 float**、float** 和 unsigned long 的 C 函数定义 getFuncWrapper 签名?

javascript - 使用 If 语句检查值的有效方法未在 Javascript 或 JQuery 中使用

javascript - 通过连接多个数组来创建列表矩阵

javascript - d3.scaleSequential "interpolator is not a function"

jquery - 我如何更改jquery中新添加行的行背景颜色

php - 包含 PHP 代码的 Javascript 字符串变量

jquery点击函数问题

java - Java 中泛型数组最简单的替代方法是什么?

php - 数组 PHP 的排列