javascript - 触发 dayClick of fullCalendar with agendaDay view

标签 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');
});

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

最佳答案

尝试使用 sibling

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>

关于javascript - 触发 dayClick of fullCalendar with agendaDay view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54873411/

相关文章:

fullcalendar - 在周 View 中仅显示特定时间范围

javascript - jQuery请求一个url列表同时限制并发请求的最大数量

javascript - 是否可以迭代 JavaScript 闭包中的所有属性?

Jquery 未选中带有单选按钮的复选框

jquery - 表单验证 : Click Submit not Trigger Validations

javascript - 更改月份时清除过滤器

javascript - 使全日历滚动到当前时间?

javascript - SoundCloud 如何在他们的移动网站上自动播放下一首歌曲?

javascript - try..catch 未捕获异步/等待错误

javascript - 无法隐藏我使用 javascript 和 jquery 生成的 html 元素