2011-03-04 78 views
7

可能重复:
Inserting new table row after the first table row using JQuery如何在一个表的第一个tr之后加上tr?

我已填充我的表中的TR和我想要的firts TR后加前缀。我使用这个:

$('#myTable').prepend($tr); 

像往常一样,它增加了我的新的顶端。

我该如何添加它作为第二?

+0

退房jQuery的API上的[第一选择器](http://api.jquery.com/first-selector/) – 2011-03-04 12:43:02

+2

我搜索了我的问题是可能的重复。我发现我的答案:http://stackoverflow.com/questions/4849794/inserting-new-table-row-after-the-first-table-row-using-jquery – kamaci 2011-03-04 12:44:20

回答

26

您将要使用jquery after,像这样:

$('#myTable tr:first').after($tr); 
+0

感谢您的 – marknt15 2017-03-24 05:44:11

6

你可以做一件事,保持表格的第一个tr到<thead>,并将其余的tr保存到表格的<tbody>

现在做

$('#myTable tbody').prepend($tr); 
0

您需要使用.after

$('#myTable > tbody > tr:first').after($tr); 
相关问题