繁体   English   中英

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

[英]How to append a table row towards last of a row with a specific class?

我试图将一行附加到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); } // 

就像是

$('#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/

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

<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>

您可能不需要标题,但您可以将所有“记录”粘贴在肢体内,将分页粘贴在足部。

这样你可以使用

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

它将在行的末尾附加行,但在分页内的分页之前。

尝试...

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM