简体   繁体   English

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

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

I'm trying to append a row to the html format of an asp data grid. 我试图将一行附加到asp数据网格的html格式。 My grid is having paging and that too is converted as a row in the html format. 我的网格正在分页,并且也将其转换为html格式的行。 So, I added a class to the rows with the actual records. 因此,我在具有实际记录的行中添加了一个类。 Now, i need to append an html table row to the grid. 现在,我需要将html表行添加到网格。 This should be appended towards the end of the records. 这应该附加到记录的末尾。 Somebody knows how to do this? 有人知道该怎么做吗?

Table Structure: 表结构:

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

Script: 脚本:

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

Something like 就像是

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

Or like Angel's comment, select directly the last tr.clientData : 或像Angel的评论一样,直接选择最后一个tr.clientData:

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

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

A better way would be to use the correct table tags. 更好的方法是使用正确的表标签。

ie

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

You may not need to have a header, but you can stick all of your "records" within the tbody and your pagination within the tfoot. 您可能不需要标题,但您可以将所有“记录”粘贴在肢体内,将分页粘贴在足部。

This way you can use 这样你可以使用

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

Which will append the row to the end tbody, but before the pagination within the tfoot. 它将在行的末尾附加行,但在分页内的分页之前。

尝试...

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

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

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