【发布时间】:2019-06-12 09:48:00
【问题描述】:
<button type="button" class="btn btn-default" id="add_supplier">Add Supplier</button>
<table class="table table-bordered" id="supplier_table">
<thead>
<tr id="first-header">
<th></th>
<th></th>
<th colspan="2">Supplier</th>
</tr>
<tr id="second-header">
<th>Item</th>
<th>Qty</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" class="form-control" id="usr" value="Mouse" readonly=""></td>
<td><input type="text" class="form-control" id="usr" value="10" readonly=""></td>
<td><input type="text" class="form-control" id="price"></td>
<td><input type="text" class="form-control" id="total"></td>
</tr>
<tr>
<td><input type="text" class="form-control" id="usr" value="Keyboard" readonly=""></td>
<td><input type="text" class="form-control" id="usr" value="20" readonly=""></td>
<td><input type="text" class="form-control" id="price"></td>
<td><input type="text" class="form-control" id="total"></td>
</tr>
<tr>
<td><input type="text" class="form-control" id="usr" value="Monitor" readonly=""></td>
<td><input type="text" class="form-control" id="usr" value="30" readonly=""></td>
<td><input type="text" class="form-control" id="price"></td>
<td><input type="text" class="form-control" id="total"></td>
</tr>
</tbody>
</table>
这是添加列(追加)
$(function() {
$('#add_supplier').click(function() {
$('#supplier_table > thead > tr#first-header').append(
'<th colspan="2">Supplier</th>'
);
$('#supplier_table > thead > tr#second-header').append(
'<th>Price</th>' +
'<th>Total</th>'
);
$('#supplier_table > tbody > tr').append(
'<td><input type="text" class="form-control" id="price"></td>' +
'<td><input type="text" class="form-control" id="total"></td>'
);
});
});
演示链接:JSFIDDLE
【问题讨论】:
-
请用内嵌图片发布描述性问题。
-
请分享您的代码
-
请查看更新图片。这就是我试图实现的第二个价格列来自附加。第一个价格列有效。但在第二列价格没有。
-
最后的评论应该是对问题的编辑。
-
请分享您的代码,以便我们看到问题。
标签: javascript jquery