gpt4 book ai didi

javascript - jQuery 找不到附加元素

转载 作者:行者123 更新时间:2023-12-02 14:09:10 24 4
gpt4 key购买 nike

我正在尝试破解 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com