简体   繁体   English

如何选择表格的最后一行?

[英]How to select last row of a table?

I have the following div: 我有以下div:

<div data-object-id="dsOrders" class = "OrderList" >

    <div class="table-responsive m-y-1">
        <table class="table">
            <thead>
                <tr>
                    <th style="width:110px;">ID</th>
                    <th style="width:110px;"> Order Date</th>
                </tr>

                <!-- FILTER ROW -->
                <tr>
                    <td>
                        <input data-search="OrderID" class="form-control form-control-sm">
                    </td>
                    <td>
                        <input data-search="OrderDate" class="form-control form-control-sm">
                    </td>
                </tr>
            </thead>

            <tbody>

                <tr data-repeat data-active>
                    <td data-field="OrderID" class = "OrderID"></td>
                    <td data-field="OrderDate"></td>
                </tr>
            </tbody>
        </table>
    </div>


</div>

How do I make it select the last row of it with javascript or jquery? 如何使用javascript或jquery选择它的最后一行? I've tried doing it like this 我已经尝试过这样做

$("[.OrderList][tr:last]").focus();

But with no success 但是没有成功

使用此代码:

.OrderList >.table > tbody > tr:last-child { background:#ff0000; }

Try this : 尝试这个 :

$('#yourtableid tr:last').attr('id');

or this: 或这个:

$("#TableId").find("tr").last();

Hope this if helpful :) 希望这对您有帮助:)

$('#yourtableid tr:last').attr('id').focus();

or 要么

$('#yourtableid tr:last')[0].focus();

should work. 应该管用。

 console.log($(".OrderList table tr:last").html()) 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div data-object-id="dsOrders" class = "OrderList" > <div class="table-responsive my-1"> <table class="table"> <thead> <tr> <th style="width:110px;">ID</th> <th style="width:110px;"> Order Date</th> </tr> <!-- FILTER ROW --> <tr> <td> <input data-search="OrderID" class="form-control form-control-sm"> </td> <td> <input data-search="OrderDate" class="form-control form-control-sm"> </td> </tr> </thead> <tbody> <tr data-repeat data-active> <td data-field="OrderID" class = "OrderID"></td> <td data-field="OrderDate"></td> </tr> </tbody> </table> </div> </div> 

 console.log($(".OrderList tr").last().html()) 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div data-object-id="dsOrders" class = "OrderList" > <div class="table-responsive my-1"> <table class="table"> <thead> <tr> <th style="width:110px;">ID</th> <th style="width:110px;"> Order Date</th> </tr> <!-- FILTER ROW --> <tr> <td> <input data-search="OrderID" class="form-control form-control-sm"> </td> <td> <input data-search="OrderDate" class="form-control form-control-sm"> </td> </tr> </thead> <tbody> <tr data-repeat data-active> <td data-field="OrderID" class = "OrderID"></td> <td data-field="OrderDate"></td> </tr> </tbody> </table> </div> </div> 

尝试此代码,您可以通过以下方法实现它:

$('#first table:last tr:last')

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

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