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/
精彩评论