【发布时间】:2018-05-31 23:23:48
【问题描述】:
这里是 html(只是 td 元素。这是由 fullcalendar 生成的)
<td class="fc-widget-content"> //can reach till here
<div style="height: 37px;">
<div class="fc-event-container" style="height: 0px;"></div>
<div class="fc-bgevent-container">
//want to target below element
<div class="fc-bgevent" style="background-color: rgb(0, 0, 0); left: 0px; right: -101px;"></div>
</div>
</div>
</td>
在 jquery 中使用事件委托时,无法定位到元素下方。
$("#pricing-calendar").on("click",".fc-bgevent",function(event){
console.log($(this).data());
});
但如果我这样做,它会起作用(这是我能到达的最接近的 .fc-bgevent div)
$("#pricing-calendar").on("click",".fc-widget-content",function(event){
console.log($(this).data());
});
谁能告诉我如何做到这一点?
这里是fiddle(只有静态内容(只有星期五 1 有事件类,所以点击时应该触发))
更新
如果有人对 fullcalendar 有同样的问题,请查看我的回答 here
【问题讨论】:
-
尝试使用选择器:
$("#pricing-calendar").on("click",".fc-widget-content > div > .fc-bgevent",function(event){ console.log($(this).data()); });我没有测试过。 -
创建一个重现问题的演示
-
@charlietfl 用小提琴更新
-
@Alee 不会工作
-
@Abhilash 请查看我编辑的答案。
标签: jquery fullcalendar