如何将表行追加到具有特定类的行的最后一行?

时间:2012-07-19 12:37:23

标签: javascript jquery asp.net

我试图在asp数据网格的html格式中追加一行。我的网格正在进行分页,并且也会以html格式转换为一行。所以,我在具有实际记录的行中添加了一个类。现在,我需要在网格中附加一个html表格行。这应该附在记录的末尾。有人知道怎么做吗?

表格结构:

<table>
    <th>
    </th>
    <tbody>
        <tr class="clientData">1</tr>
        <tr class="clientData">2</tr>
        <tr class="clientData">3</tr>
        <tr>Exclude This Row</tr>
        <tr>Exclude This Row</tr>
    </tbody>
</table>

脚本:

{ $("#ctl00_Content_GrdCustomer tbody").append(selCustomersRow); } // 

3 个答案:

答案 0 :(得分:1)

这样的东西
$('#ctl00_Content_GrdCustomer tbody tr.clientData').last().after(selCustomersRow);

或者像Angel的评论一样,直接选择最后一个tr.clientData:

$('#ctl00_Content_GrdCustomer tbody tr.clientData:last').after(selCustomersRow);

http://api.jquery.com/after/

答案 1 :(得分:0)

更好的方法是使用正确的表格标签。

<table>
    <thead>
        <tr>
            <td>Column header 1</td>
            <td>Column header 2</td>
            <td>Column header 3</td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Column 1</td>
            <td>Column 2</td>
            <td>Column 3</td>
        </tr>
        <tr>
            <td>Column 1</td>
            <td>Column 2</td>
            <td>Column 3</td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td>Column footer 1</td>
            <td>Column footer 2</td>
            <td>Column footer 3</td>
        </tr>
    </tfoot>
</table>

你可能不需要一个标题,但你可以将所有“记录”放在tbody中,并将你的分页放在tfoot中。

这样你可以使用

$("#ctl00_Content_GrdCustomer tbody").append(selCustomersRow);

将行附加到末尾tbody,但是在tfoot中的分页之前。

答案 2 :(得分:-1)

试试......

  { $("#ctl00_Content_GrdCustomer tbody tr").last().append(selCustomersRow); }