这是我的看法
我试图使用此方法访问行索引
$("input.deliverQty").focusout(function (e) {
var table = document.getElementById('invoiceDetailTbl');
var DeliverQty = $(this).val();
var rowId = $(this).closest('tr').attr('rowIndex');
//var OrderQty = $(this).closest('tr').find('input.payingAmt').val();
var OrderQty = table.rows[parseInt(rowId) + 1].cells[2].childNodes[0].data;
但结果不确定
我像这样附加我的桌子
for (var i = 0; i < data[0].itemDetails.length; i++) {
itmCode = data[0].itemDetails[i].item_Code;
itmName = data[0].itemDetails[i].item_Name;
OQty = parseInt(data[0].itemDetails[i].item_Qty);
//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>" + itmCode + "</td>" + "<td>" + itmName + "</td>" + "<td>" + OQty + "</td>" + "<td>" + '<input type="text" class="deliverQty form-control input-sm" style="width: 100px;" placeholder="Deliver Qty" id="dqty">' + "</td>" + "<td>" + '<span class="glyphicon glyphicon-trash"></span>' + "</td>" + "</tr>");
//noOfItems = parseInt(noOfItems) + parseInt(OQty);
//noOfProducts = parseInt(noOfProducts) + 1;
}
最佳答案
rowIndex
不是属性,因此请尝试.prop()
var log = (function() {
var $log = $('#log');
return function(msg) {
$('<p/>', {
text: msg
}).appendTo($log)
}
})();
jQuery(function() {
$('tr input').each(function() {
var rowId = $(this).closest('tr').attr('rowIndex');
log('attr: ' + rowId);
rowId = $(this).closest('tr').prop('rowIndex');
log('prop: ' + rowId);
})
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table>
<tr>
<td>
<input />
</td>
</tr>
<tr>
<td>
<input />
</td>
</tr>
</table>
<div id="log"></div>
关于javascript - 如何获得所选行的行索引,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26479642/