jquery:tr中的td的序数

deo*_*oll 4 jquery ordinals html-table

我在html表中有一行只包含图像.(这恰好也是第一行).这些图像也用于点击事件.在尝试处理click事件时,我可以找到它的父<td>元素(即元素).但我想知道它在表格行中的相对序数(<tr>).

rek*_*o_t 5

您可以找到具有该index()功能的序数:

$('td img').click(function() {
   var ordinal = $(this).closest('tr').children().index($(this).parent());
   // ...
});
Run Code Online (Sandbox Code Playgroud)