0

我有一个具有以下结构的表:

<table id="tblBranchCoverage">
    <thead>...</thead>
    <tbody>
        <tr class="coverageRow">
            <td class="countyCovered">
                <label="branchCountyCovered coverageDisplay">Barrow</label>
                                ...
            </td>
            <td>
                ...
            </td>
        </tr>
        <tr class="coverageRow">
            <td class="countyCovered">
                <label="branchCountyCovered coverageDisplay">Cook</label>
                ...
            </td>
            <td>
                ...
            </td>
        </tr>
    </tbody>
</table>

我正在尝试查找具有特定文本标签的行。

除了这个(这是行不通的),我想不出任何东西:

$("#tblBranchCoverage tbody tr").find('label[text="Barrow"]')

我通过在控制台中测试选择器来验证它不起作用。

这样做的正确方法是什么?

4

2 回答 2

1

尝试包含:

http://docs.jquery.com/Selectors/contains#text

那么您应该可以使用父母进行过滤:

http://docs.jquery.com/API/1.2/Traversing/parents

所以它应该是这样的

$("label:contains('Barrow')").parents("tr.coverageRow");
于 2013-01-29T16:44:27.947 回答
0

这应该可以解决问题,它将根据标签文本过滤您的选择

$("#tblBranchCoverage tbody tr label").filter(function(){
  return (/Barrow/i).test($(this).text())
})

或者

$("#tblBranchCoverage tbody tr label").filter(function(){
  return $(this).text() == "Barrow";
})
于 2013-01-29T16:39:13.620 回答