触发日点击带有议定日视图的全日历

时间:2019-02-25 19:32:01

标签: javascript jquery fullcalendar

考虑此HTML

<tr class="fc-slot120 ">
    <th class="fc-agenda-axis fc-widget-header">4PM</th>
    <td class="fc-widget-content">
        <div style="position: relative;"></div>
    </td>
</tr>

单击td.fc-widet-content后,将按预期方式调用dayClick事件。我想将此功能扩展到有时间的th,以便更轻松地进行超量预订。确实会调用此代码,但不会触发dayClick。

$('.fc-agenda-axis.fc-widget-header').click(function() {
    $(this).find('td.fc-widget-content').trigger('click');
});

有什么想法如何触发内容dayClick上的td事件?如果我直接单击td.fc-widget-content元素,则会按预期触发dayClick。

1 个答案:

答案 0 :(得分:2)

尝试使用兄弟姐妹

jQuery(document).ready(function($) {
   
    $('.fc-widget-header').click(function() {
      $(this).siblings('.fc-widget-content').trigger('click');
  });
     
    $('.fc-widget-content').on('click', function() {
      console.log('click')
      alert('.fc-widget-content clicked')
    })
});
.fc-widget-header {
  height: 100px;
  width: 100px;
  background-color: red;
  color:white
}

.fc-widget-content {
  height: 100px;
  width: 100px;
  background-color: blue;
  color: white;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr class="fc-slot120">
    <th class="fc-agenda-axis fc-widget-header">4PM</th>
    <td  class="fc-widget-content">
         testt
        <div style="position: relative;"></div>
    </td>
</tr>
</table>