我正在尝试将表行附加到现有表中。
这就是我的表格的结构:
<div id="productListContainer">
<table id="productListTable">
<thead>
<tr>
<td>
#
</td>
<td>
Product Name
</td>
<td>
Price
</td>
<td>
Quantity
</td>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
使用以下功能,我试图追加一个新的表格行:
function(data) {
if (data.productAdded !== "undefined") {
$("#productListTable tr").append().html(data.productAdded);
}
}
成功地附加了一行。但是,如果我选择触发相同功能的不同项目,则添加的表行将被新的行覆盖。
我在 ajax 调用中使用此函数作为成功消息。
'data' 是一个 JSON 对象,其中包含 productAdded,它本身就是作为字符串的表格行。