我使用for循环将数据追加到表
for (var i = 0; i < data.length; i++) {
date = data[i].inv_Date;
invDate = date.substring(0, 10);
billNo = data[i].Bill_No;
netAmt = parseFloat(data[i].Net_Amt).toFixed(2);
paidAmt = parseFloat(data[i].Paid_Amt).toFixed(2);
balance = (parseFloat(netAmt) - parseFloat(paidAmt)).toFixed(2); //id = "damt['+i+']"
$("#invoiceDetailTbl tbody").append("<tr id=" + i + ">" + "<td>" + invDate + "</td>" + "<td>" + billNo + "</td>" + "<td>" + netAmt + "</td>" + "<td>" + paidAmt + "</td>" + "<td>" + '<input type="text" class="discountAmt form-control input-sm" style="width: 100px;" placeholder="Discount Amt" id="damt" name="damt' + i + '">' + "</td>" + "<td>" + '<input type="text" class="payingAmt form-control input-sm" style="width: 100px;" placeholder="Paying Amt" id="pamt">' + "</td>" + "<td>" + balance + "</td>" + "<td>" + '<span class="glyphicon glyphicon-trash"></span>' + "</td>" + "</tr>");
totalAmt = totalAmt + parseFloat(netAmt);
totalBalance = totalBalance + parseFloat(balance);
}
我正在使用读取文本框的值
var PayingAmtValue = $(this).closest('tr').children('td.discountAmt').val();
但总会得到空值。我也会尝试使用
var table = document.getElementById('invoiceDetailTbl');
var DiscountAmtValue = $(this).val();
var rowId = $(this).closest('tr').attr('id');
PayingAmtValue = $(table.rows.item(rowId + 1).cells[5]).find('input').val();
但浏览器返回未捕获的TypeError:无法读取null的属性“ cells”
您已discountAmt
申请input
,尚未申请td
。你必须找到input
其为具有class="discountAmt"
内td
。
// this will find children 'td' having class="discountAmt"
var PayingAmtValue = $(this).closest('tr').children('td.discountAmt').val();
将上面的代码更改为
// this will find input with 'class="discountAmt"'
var PayingAmtValue = $(this).closest('tr').find('input.discountAmt').val();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句