我正在使用 PHP,并且我有一个想要动态填充的表。
<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 来完成此操作,也许还可以利用一些 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>
请注意,我想保留一个标题行!
我想在标题行和带有“最终内容”的行之间插入行。最后一行始终存在。
如果我收到您的询问:
<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>
Fiddle
我是一名优秀的程序员,十分优秀!