javascript - jQuery 找不到附加元素

标签 javascript jquery fullcalendar

我正在尝试破解 fullcalendar,以便在我的日历中每行显示多个事件。因此,为了做到这一点,我想迭代这些行并重新组织它们的内容。但是,jQuery 无法 find() 这些行。

<div class="fc-content-skeleton">
    <table>
        <thead>
            <tr>
                <td class="fc-day-number fc-mon fc-past" data-date="2016-09-26">26</td>
                <td class="fc-day-number fc-tue fc-past" data-date="2016-09-27">27</td>
                <td class="fc-day-number fc-wed fc-past" data-date="2016-09-28">28</td>
                <td class="fc-day-number fc-thu fc-past" data-date="2016-09-29">29</td>
                <td class="fc-day-number fc-fri fc-today fc-state-highlight" data-date="2016-09-30">30</td>
                <td class="fc-day-number fc-sat fc-other-month fc-future" data-date="2016-10-01">1</td>
                <td class="fc-day-number fc-sun fc-other-month fc-future" data-date="2016-10-02">2</td>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td rowspan="2"></td>
                <td class="fc-event-container" rowspan="2">
                    <a class="fc-day-grid-event fc-h-event fc-event fc-start fc-end event-free" data-url=""></a>
                </td>
                <td rowspan="2"></td>
                <td class="fc-event-container">
                    <a class="fc-day-grid-event fc-h-event fc-event fc-start fc-end event-mine" data-url=""></a>
                </td>
                <td class="fc-event-container">
                    <a class="fc-day-grid-event fc-h-event fc-event fc-start fc-end event-free" data-url=""></a>
                </td>
                <td rowspan="2"></td>
                <td rowspan="2"></td>
            </tr>
            <tr>
                <td class="fc-event-container">
                    <a class="fc-day-grid-event fc-h-event fc-event fc-start fc-end event-taken" data-url=""></a>
                </td>
                <td class="fc-event-container">
                    <a class="fc-day-grid-event fc-h-event fc-event fc-start fc-end event-free" data-url=""></a>
                </td>
            </tr>
        </tbody>
    </table>
</div>

我能够访问 .fc-content-sculpture 下的 table 标记。但是当我调用 'find("table").children()' 时,它只返回我需要的 thead 而不是 tbody 。我在获取并附加所有事件后执行此操作。

编辑

函数调用如下:

    $(document).on("ready turbolinks:load", function(){
       //.....

       $("#calendar").fullCalendar(calendarOpt);
       $("#calendar").reorganizeEvents();

       //.....
}):

函数本身:

(function($) {
   $.fn.reorganizeEvents = function(){
    if(reorgHandler == false){
      $(this).fullCalendar('render');
      var $dayContainers = $(this).find(".fc-row .fc-content-skeleton table")
           .children(); //obtaining children of the table in .fc-skeleton.
             // Supposed to be <thead> and <tbody>
          console.log($dayContainers); //successfully finds table
          $dayContainers.each(function(index){ 
            console.log($(this)); //shows only <thead> as a single child
          });
          reorgHandler = true;
        }
      }
    }(jQuery));

最佳答案

将 JavaScript 放在页面底部、</body> 关闭之前

或使用

$( document ).ready(function(){
  $(".fc-content-skeleton").find("table").children();
})

关于javascript - jQuery 找不到附加元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39799541/

相关文章:

javascript - 从函数返回值并放入单独函数中的变量

javascript - 使用具有相同类名的 jQuery 选择 div

javascript - ES6 类 'this' 用于非类方法

html - 使用 jquery 展开和折叠表行 (tr)

c# - 检查日期范围是否在 fullcalendar.io 显示的另一个日期范围内

javascript - 取消选中复选框时更改选择下拉列表的值

javascript - 图像翻转,文字出现在别处

javascript - 让选择器覆盖选项卡以根据需要调整大小和移动?

javascript - 如何在全日历的列中拆分单日?

jquery - qTip 未出现在 jQuery 完整日历上