使用 jquery datetimepicker 输入事件关闭时如何在 table 行中找到最接近的表单元素

How to find closest form element in table row when using jquery datetimepicker input event close

我正在使用 xdan/datetimepicker jquery 库来获取日期输入。日期更改后,我需要更改 table 中同一行中的某些表单元素。这是代码

$('.tstartdate').datetimepicker({
    format:'d/m/Y h:i A',
      formatTime:'h:i A', step:1,
      onClose: function (ct, $i) {
            $(this).closest('tr').find('td .enddate').val("zazazas");
            }
      });
@:<td valign="top"><input type='text' class="tstartdate" value='@etadatetime' style='width:150px!important;'  name='Startdate' @flfirst /></td>
@:<td valign="top">
@:  <select name="Duration" class="selectduration">
@:  <option value="">Duration</option>
@:  <option value="12">12 Hours</option>
@:  <option value="24">24 Hours</option>
@:  <option value="48">48 Hours</option>
@:  <option value="72">72 Hours</option>
@:  </select>
@:</td>
@:<td valign="top"><input type='text' class='enddate' style='width:150px!important;'  name='Enddate' placeholder='To Date'/></td>

The documentation 建议输入作为第二个参数传递($i 在您的代码中)并且它已经是一个 jQuery 实例,因此:

$('.tstartdate').datetimepicker({
    format:'d/m/Y h:i A',
      formatTime:'h:i A', step:1,
      onClose: function (ct, $i) {
          $i.closest('tr').find('td .enddate').val("zazazas");
// -------^^
      }
});

当然假设您要更新的元素在 td 内并且具有 class enddate.

使用 this 引用事件处理程序所挂接的 DOM 元素调用事件处理程序是 jQuery 和 well-behaved 中的 overwhelmingly-common 约定 jQuery 插件,但它不是通用的。这个似乎更喜欢不同的 API.