我想创建一个表格来在此处输入代码
插入、更新
和删除
。
这个想法是用表格替换表单,例如,在填充第一行或动态创建第二行或放置按钮添加行和之后,创建一个仅包含标题和准备插入数据的空行的表格返回写入内容和插入等。 我正在尝试这种方式,但是我无法在列中写入然后进行插入:
<table id="products-table">
<tbody>
<tr>
<th>Produto</th>
<th>Código</th>
<th>Quantidade</th>
<th>Preço</th>
<th>Ações</th>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>
<button onclick="RemoveTableRow(this)" type="button">Remover</button>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="5" style="text-align: left;">
<button onclick="AddTableRow()" type="button">Adicionar Produto</button>
</td>
</tr>
</tfoot>
</table>
<script>
(function($) {
AddTableRow = function() {
var newRow = $("<tr>"); var cols = "";
cols += '<td> </td>';
cols += '<td> </td>';
cols += '<td> </td>';
cols += '<td> </td>';
cols += '<td>';
cols += '<button onclick="RemoveTableRow(this)" type="button">Remover</button>';
cols += '</td>';
newRow.append(cols);
$("#products-table").append(newRow);
return false;
};
})(jQuery);
</script>
但是我疑问,创建一个表格来替换html中的表单有意义吗?
最佳答案
这确实有道理,我建议你看看DataTable这使您能够通过适当的回调等来处理此类用例。唯一的限制是您需要 jQuery。
关于php - 创建空表并插入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56808942/