我使用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:无法读取属性'cell'为null
答案 0 :(得分:0)
您已将discountAmt
应用于input
,而不是td
。您必须在input
内找到class="discountAmt"
{。}}。
td
将上述代码更改为
// this will find children 'td' having class="discountAmt"
var PayingAmtValue = $(this).closest('tr').children('td.discountAmt').val();