jQuery是否有一种简单的方法来返回所有者复选框(用于深层嵌套的复选框(或输入))?这是我的意思的示例:

<form>
    <table>
        <thead>
            <tr>
                <td>123</td>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <td><input type="checkbox" class="checkall" /></td>
            </tr>
        </tfoot>
    </table>
</form>

然后我有以下jQuery代码:
$('checkbox.checkall').each(function() {
    // Access form element of the checkbox here
});

在上面的示例中,我想获取复选框所属的表单。通常,我可以使用链接的parent()方法执行此操作,但是复选框可能并不总是与根表单元素的嵌套深度相同。

抱歉,如果不清楚,但很难解释。

最佳答案

获取closest表单

$("input[type=checkbox]").closest("form");
从jQuery API:

09-25 17:20
查看更多