我正在使用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,我想要添加数据以上 标有&#34;最后消息&#34;
的行每个新行都有数据来填充每个单元格。
是否有一些功能可以执行此操作使用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>
请注意,我想要保留一个HEADER ROW!
我想在标题行和行之间插入行&#34; Final something&#34;。
最后一行始终存在。
答案 0 :(得分:1)
如果我收到你的疑问:
<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>