我正在开一张发票,其中的顺序有一个以上的产品订单明细表,其中产品列的编号为no。对于每个添加的产品行逐个用户,当用户在其中添加一些产品详细信息行时,由以下代码自动更新产品列序列的数量:
var n = $(".detail tr").length-0)+1;
var tr = '<td class="no">'+ n +'</td>'
当用户希望删除添加的行之间的产品详细信息之一时,不需要。序列列不更新我是怎么做的?
发布于 2015-10-15 16:01:55
$(function()
{
// Add Row
$("#add").click(function()
{
addnewrow();
});
// Remove Row
$("body").delegate('#remove','click',function()
{
$(this).parent().parent().remove();
});
});
function addnewrow()
{
var tr = '<tr>' +
'<td class="count"></td>'+
'<td><input type="text" class="productname"></td>'+
'<td><input type="button" value="-" id="remove"></td>'+
'</tr>'
$(".detail").append(tr);
}
body {counter-reset:section;}
.count:before
{
counter-increment:section;
content:counter(section);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<table>
<thead>
<tr>
<th><input type="button" value="+" id="add"></th>
</tr>
</thead>
<tbody class="detail">
<tr>
<td class="count"></td>
<td><input type="text" class="productname"></td>
<td><input type="button" value="-" id="remove"></td>
</tr>
<tbody>
</table>
发布于 2017-01-25 20:34:12
//Update Name attribte Increment in each row
$('#dataTable tbody tr').each(function () {
var this_row = $(this);
var rowIndex = this_row.index();
$.each(this_row.find(':input'), function (i, val) {
var oldName = $(this).attr('name');
var newName = oldName.replace(/\d+/, rowIndex);
$(this).attr('name', newName);
});
});
https://stackoverflow.com/questions/33159690
复制