0
我想刪除行x後的表中的所有行,其中x是切換的數字。以下不工作:使用jQuery刪除指定行後表中的所有行
$("#comps-table tbody tr:gt(x)").remove();
也不:
$('#comps-table tbody tr').gt(x).remove();
我想刪除行x後的表中的所有行,其中x是切換的數字。以下不工作:使用jQuery刪除指定行後表中的所有行
$("#comps-table tbody tr:gt(x)").remove();
也不:
$('#comps-table tbody tr').gt(x).remove();
x
是一個變量,所以你需要使用字符串連接。
$("#comps-table tbody tr:gt(" + x + ")").remove();
或首選的方法是使用片()
$('#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();
}
});
還沒有測試它,但它應該讓你在正確的方向
真,再加上它感覺不到效率。阿倫P Johny的答案更適合 - 呃 – Varinder