[英]How to append in table in JQuery?
Can you please tell me how to how to append contend to a table? 能否请您告诉我如何添加竞争表? I want to append my content after first row.
我想在第一行之后附加我的内容。 Here is my fiddle:
这是我的小提琴:
In this i am appending in this div 在这个我在这个div后面
$('#test ').html(buildNav(testData.testCaseList)).trigger('create');
I don't want this. 我不要这个 I will remove that div and uncomment that table.
我将删除该div并取消注释该表。
What should I write in that line so that it appends after the row of table? 我应该在该行中写些什么,以便使其追加到表的行之后?
$('#test ').html(buildNav(testData.testCaseList)).trigger('create');
Try something like that 试试这样的东西
HTML HTML
<table>
<tr>
<td>ONE</td>
</tr>
<table>
Appending 追加
$('table').append('<tr><td>TWO</td></tr>'); //And so on...
For some reason, the create
event prepends the #test
div to the table instead of appending it. 出于某种原因,
create
事件#test
div附加到表中,而不是附加到表中。 I solved it creating a tbody with an ID, and appending to it when creating new tests. 我解决了创建带有ID的正文的问题,并在创建新测试时将其附加到了正文中。
HTML HTML
<div class="parallelTestCases">
<table id="table_parallelTestCases" width="100%" border="1">
<thead>
<tr>
<td>
<a href="javascript:createParallelTestCases()" data-icon="plus" data-role="button" data-mini="true" data-theme="a">Add Test Case</a>
</td>
<td>
<select onchange="changeTestSuiteFlip(this)">
<option value="SEQUENCE">Sequential</option>
<option value="PARALLEL">Parallel</option>
</select>
</td>
</tr>
</thead>
<tbody id="tabletbody">
<div id="test"></div>
</tbody>
</table>
</div>
JS, createParallelTestCases function JS,createParallelTestCases函数
createParallelTestCases=function() {
$('#test').html(buildNav(testData.testCaseList)).trigger('create');
$('#test').appendTo('#tabletbody');
};
To append to <table>
after first row, you can use: 要在第一行之后追加到
<table>
,可以使用:
$('table tr:first').after('<tr><td></td></tr>');
If you are sure you have <tbody>
tag inside, you can use the code below. 如果确定其中包含
<tbody>
标记,则可以使用下面的代码。
Please note that there will always be a <tbody>
in the DOM but only if there is at least one row. 请注意,DOM中总是有一个
<tbody>
,但<tbody>
是至少有一行。 If you have no rows, there will be no <tbody>
unless you have specified one yourself. 如果没有行,除非您自己指定一个,否则不会有
<tbody>
。 So my advice is - make sure specified always <tbody>
and then use this code: 所以我的建议是-确保始终指定
<tbody>
,然后使用此代码:
$('table > tbody:first').append('<tr><td></td></tr>');
You can include anything within the after()
method as long as it's valid HTML. 您可以在
after()
方法中包含任何内容,只要它是有效的HTML。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.