通过使用jQuery在td中单击获取表ID [英] Get table id by click in td using jQuery
本文介绍了通过使用jQuery在td中单击获取表ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在包含多个输入字段的表头中有一个tr.
I have a tr in a table header that contains several input fields.
是否可以通过单击这些输入字段之一来获取父表的ID?
Is there a way that by click on one of these input fields I can get the id of the parent table ?
我的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()
In the click handler you can use .closest()
$(this).closest('table').attr('id')
这篇关于通过使用jQuery在td中单击获取表ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文