[英]Find second last row from table
I have table with dynamic row and I want to find second last row from table.我有一个带有动态行的表,我想从表中找到倒数第二行。
HTML Code HTML 代码
<table class="table">
<tr><td>1</td></tr>
<tr><td>2</td></tr>
<tr><td>3</td></tr>
<tr><td>4</td></tr>
<tr><td>5</td></tr>
<tr><td>6</td></tr>
<tr><td>7</td></tr>
<tr><td>8</td></tr>
<tr><td>9</td></tr>
<tr><td>10</td></tr>
</table>
jQuery Code jQuery 代码
alert($(".table").find("tr:last").find("td").html());
I tried with tr:last
but it give me last row with value 10
.我尝试使用
tr:last
但它给了我最后一行的值10
。
Expected Output预计 Output
Second last row value 9
instead of 10
倒数第二行值
9
而不是10
使用.prev()
返回一个元素。
alert($(".table tr:last").prev().find("td").html());
With nth-last-child: 与n-last-child:
alert($(".table").find("tr:nth-last-child(2)").find("td").html());
You could also make it a single selector: 你也可以把它变成一个选择器:
alert($(".table tr:nth-last-child(2) td").html());
试试这个
$('.table tr:last').prev('tr').html()
使用.eq()和-1指定最后一个元素...
alert($(".table").find("tr").eq(-2).find("td").html());
Second Last Row Remove倒数第二行删除
$('tbody tr:last', $("#ctl00_MainContent_rdgImgDig_ctl00")).prev().remove();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.