[英]Using jQuery to remove all rows in a table after a specified row
我想删除x后面的表格中的所有行,其中x是向上切换的数字。 以下内容不起作用:
$("#comps-table tbody tr:gt(x)").remove();
也没有:
$('#comps-table tbody tr').gt(x).remove();
x
是一个变量,因此您需要使用字符串连接。
$("#comps-table tbody tr:gt(" + x + ")").remove();
或首选方式是使用slice()
$('#comps-table tbody tr').slice(x).remove();
尝试这个:
var after = 5; // remove after row number 5
$('#comps-table tbody tr').each(function() {
var $row = $(this);
var rowNumber = $row.index();
if ( rowNumber >= after ) {
$row.remove();
}
});
Havent已对其进行了测试,但它应该为您提供正确的方向
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.