开发者

Select special index with special attribute value

consider this code:

<table border="1" width="100%" id="list">
    <tr>
        <th>name</th>
        <th>age</th>
        <th>city</th>
    </tr>
    <tr>
        <td o="1">aaa</td>
        <td o="2">20</td>
        <td o="3">zzzzzzzz</td>
    </tr>
    <tr>
        <td o="2">hhhhhhh</td>
        <td o="3">55</td>
        <td o="1">aaaaaaa</td>
    </tr>
    <tr>
        <td o="3">qqqqq</td>
        <td o="1">15</td>
        <td o="2">qq</td>
    </tr>
</table>

how i can sele开发者_运维知识库ct ROW (TR) that contain TD with attribute (o=2) that appeare in column N ?!

i try this but don't work:

$("table#list tr").filter(':has(td:eq(0)[o="2"])')...


Try this

$("table#list tr").filter(function(){
  return $(this).find("td:nth-child(1)[o='2']").length > 0;
  //nth-child is indexed from 1
});


You can do it in a single selector:

$("table#list tr td:first-child[o=2]")..

Use nth-child to select cells with attribute o="2" in the second column, for example:

$("table#list tr td:nth-child(2)[o=2]")..


Try this:

function getNthChild(n) {
    return $('#list td:eq(' +n + ')[o="2"]').closest('tr');
}

jsfiddle: http://jsfiddle.net/mrchief/Bhtdr/3/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜