我的表头中有一个 tr,其中包含多个输入字段。
有没有一种方法可以通过单击这些输入字段之一来获取父表的 ID?
我的 tr 看起来像这样:
<table id="tableID">
<thead>
<tr>
<th><input type="text" name="input1" id="input1" /></th>
<th><input type="text" name="input2" id="input2" /></th>
<th><input type="text" name="input3" id="input3" /></th>
</tr>
</thead>
<tbody>
// ...
</tbody>
</table>
最佳答案
在点击处理程序中,您可以使用 .closest()
$(this).closest('table').attr('id')
关于jquery - 使用 jQuery 通过单击 td 获取表 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20175970/