使用jQuery在td中单击获取表id

use*_*510 6 jquery identifier

我在表头中有一个包含几个输入字段的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>
Run Code Online (Sandbox Code Playgroud)

Aru*_*hny 32

在单击处理程序中,您可以使用.closest()

$(this).closest('table').attr('id')