使用jquery但来自表内表的td的值

时间:2012-01-03 01:59:44

标签: jquery html-table

我想获取表t2中td内的元素的td值 我怎么能实现它? 我试过这个,但没有帮助

var test = $(.lv1 tr:nth-child(" + row2 + ")").children("td:last").children(".lv2 tr:last").children("td:last").html();

<listview1>
<itemtemplate>
    <table class="t1">
    <tr class="lv1"><td></td><td></td></tr>
    <tr class="lv1"><td colspan="2">
<listview2>
<itemtemplate>
    <table class="t2">
    <tr class="lv2">
    <td></td>
    </tr>
    <tr class="lv2">
    <td></td>
    </tr>
    </table>
</itemtemplate>
</listview2>
    </td></tr>
    </table>
</itemtemplate>
</listview1>

2 个答案:

答案 0 :(得分:2)

好的,根据您的反馈,这是我认为您所追求的。单击“转到”按钮以查看其实际效果。

http://jsfiddle.net/mSHKC/

$('#go').click( function() {
    var id = 'foo'; //hardcode id retrieval on button press
    //value of first td of first row in table.t2
    var firstTdFirstRow = $(this).closest('table.t1').find('table.t2 tr:first td:first').html();
    //value of first td of last row in table.t2
    var firstTdLastRow =  $(this).closest('table.t1').find('table.t2 tr:last td:first').html();
});

您有此评论,但我不确定这意味着什么,因为我认为您拼写错误。

 its selecting right td which i want to but while appenind its getting error

答案 1 :(得分:1)

为什么不使用更简单的东西:

$("tr.lv2:eq(0) td").text();

获得第一个这样的细胞

$("tr.lv2:eq(1) td").text();

对于第二个,依此类推

或者,如果您将索引作为变量,则可以使用eq 函数

$("tr.lv2").eq(index).find("td").text();
相关问题