2014-02-07 49 views

回答

4

x是一個變量,所以你需要使用字符串連接。

$("#comps-table tbody tr:gt(" + x + ")").remove(); 

或首選的方法是使用片()

$('#comps-table tbody tr').slice(x).remove(); 
0

試試這個:

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(); 
    } 
}); 

還沒有測試它,但它應該讓你在正確的方向

+0

真,再加上它感覺不到效率。阿倫P Johny的答案更適合 - 呃 – Varinder