jQuery 如何在桌子上的第一个 tr 之后添加 tr?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5193765/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 18:42:54  来源:igfitidea点击:

How to prepend a tr to after first tr at a table?

jqueryhtmlhtml-tableprepend

提问by kamaci

Possible Duplicate:
Inserting new table row after the first table row using JQuery

可能的重复:
使用 JQuery 在第一个表行之后插入新的表行

I have populated a tr for my table and I want to prepend it after the firts tr. I use this:

我已经为我的表填充了一个 tr,我想在 firts tr 之后添加它。我用这个:

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

As usual, it adds my new tt to the top.

像往常一样,它将我的新 tt 添加到顶部。

How can I add it as second?

如何将其添加为第二个?

回答by Mark Steggles

You will want to use jquery after, like this:

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

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

回答by jimy

You can do one thing keep the first tr to <thead>of the table and rest tr to <tbody>of the table.

你可以做一件事,保留表的第一个 tr to<thead>并保留表的 tr to <tbody>

Now do

现在做

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

回答by nickf

You need to use .after

你需要使用 .after

$('#myTable > tbody > tr:first').after($tr);