锚定到 table 中的特定 tr

Anchor to specific tr in a table

我有一个可滚动的 HTML table,根据 table 上的数据,我希望 table 从特定的 [=12] 开始显示=].上面的行可以在滚动时显示。但是当页面加载时,我需要定位到特定的 <tr>

我可以使用以下代码获取我需要定位的 <tr>。我不知道如何设置位置。

<script type="text/javascript">
    $(document).ready(function () {
        var myTr = $(".slash-price:first").closest('tr');
    });
</script>

我的 Tr 是 <tr> 我想在 table 元素中首先显示。

这应该使位置动画平滑到您使用 closest('tr'):

选择的行
<script type="text/javascript">
    $(document).ready(function () {
        var myTr = $(".slash-price:first").closest('tr');
        $('html, body').animate({
           scrollTop: $(myTr).offset().top
        }, 2000);
    });
</script> 

是的,所以我最终使用了 top - 620

var myTr = $(".slash-price:first").closest('tr');
        $('html, body').animate({
            scrollTop: $(myTr).offset().top - 620
        }, 2000);