【问题标题】:Select checkbox where tablerow contains certain text选择 tablerow 包含某些文本的复选框
【发布时间】:2012-07-05 16:23:25
【问题描述】:

我有一个有两列的表。第一列是所有复选框,第二列是属性名称列表。如何选中包含特定文本的表格单元格旁边的复选框?

这是我的桌子:

<table id="table1">
    <tr>
        <td class="SelectColumn"><span title="Select this attribute">
            <input id="chkSelected" type="checkbox" /></span> </td>
        <td>Age (required)</td>
    </tr>
</table>

这是我对 jQuery 代码的尝试:

$('#[someButton]').click(function () {
        var tableRow = $("td:contains('required')").closest('td').find('input');
        $(tableRow).attr('checked', true);
});

当我调试这段代码时,tableRow.length 返回 0。

【问题讨论】:

    标签: jquery html jquery-ui html-table


    【解决方案1】:

    我想我自己找到了答案:)

    var tableRow = $("td:contains('required')").prev().find('input');
    
    $(tableRow).attr('checked', true);
    

    有没有更优雅/高效的方法来做到这一点?

    【讨论】:

      猜你喜欢
      • 2012-07-06
      • 1970-01-01
      • 1970-01-01
      • 2020-11-08
      • 2016-11-06
      • 2022-07-21
      • 2012-06-29
      • 2020-01-28
      相关资源
      最近更新 更多