Javascript 如何插入<;tr>;变成一个<;表>;(使用PHP)
我正在使用PHP,我有一个表,我想动态填充Javascript 如何插入<;tr>;变成一个<;表>;(使用PHP),javascript,php,html,Javascript,Php,Html,我正在使用PHP,我有一个表,我想动态填充 <table> <tr> <th>This One</th> <th>That One</th> <th>The Other One</th> </tr> <tr> <td>Final This</td>
<table>
<tr>
<th>This One</th>
<th>That One</th>
<th>The Other One</th>
</tr>
<tr>
<td>Final This</td>
<td>Final That</td>
<td>Final The Other</td>
</tr>
</table>
这个
那个
另一个
最后的这个
最后那个
最后一个是另一个
我正在填充表数据onchange,我希望将数据添加到上面的
标有“Final blah”的行。
每一新行都有用于填充每个单元格的数据
是否有一些功能可以通过PHP实现这一点,mayber利用了一些JavaScript
编辑:
我想得到一个最终产品,看起来像这样:
<table>
<tr>
<th>This One</th>
<th>That One</th>
<th>The Other One</th>
</tr>
<tr> Dynamically added row. Cells already populated from database</tr>
<tr> Next row of data from the database</tr>
<tr> The next row should **ALWAYS** be the last row</tr>
<tr>
<td>Final This</td>
<td>Final That</td>
<td>Final The Other</td>
</tr>
</table>
这个
那个
另一个
动态添加行。已从数据库填充单元格
数据库中的下一行数据
下一行应**始终**为最后一行
最后的这个
最后那个
最后一个是另一个
注意,我想保留一个标题行我想在标题行和带有“Final something”的行之间插入行。
最后一行始终存在。如果我收到您的查询:
<table id="myTable">
<tr>
<th>This One</th>
<th>That One</th>
<th>The Other One</th>
</tr>
<tbody id="myid">
<tr><td>Final This</td><td>Final That</td><td>This is your Last Row</td></tr>
</tbody>
</table>
<br>
<button onclick="myCreateFunction()">Add row</button>
<script>
function myCreateFunction() {
var table = document.getElementById("myid");
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
cell1.innerHTML = "Final This";
cell2.innerHTML = "Final That";
cell3.innerHTML = "I am inserted between First and last row";
}
</script>
这个
那个
另一个
这是你的最后一排
添加行
函数myCreateFunction(){
var table=document.getElementById(“myid”);
var行=table.insertRow(0);
var cell1=行插入单元格(0);
var cell2=行插入单元格(1);
var cell3=行插入单元格(2);
cell1.innerHTML=“最终此”;
cell2.innerHTML=“最终结果”;
cell3.innerHTML=“我插入第一行和最后一行之间”;
}
使用一些ajax和jquery查找最后一行并将其添加到上面。需要动态创建
tr
,向其中添加数据并将其附加到tbody
尝试在PHP中使用echo?是什么驱动了行的添加。一旦改变什么?不管我改变什么。在更改某些内容后,在标题行下方插入一些行。否。这就是我在这里提出这个问题的原因。我希望表中的最后一行是相同的,所有新行都插入到它的上方,标题行的下方。但再看一看,也许这个答案就是我需要的答案。我只是需要对它进行很多争论。这个答案似乎忽略了我的标题行。在标题和最后一行之间没有插入任何行。您可以通过table.insertBefore(newRow,footerRow)实现这一点