我有一个使用jquery自动生成的表。我需要在该表的单元格中的keyup事件上获取行的索引号。这就是我尝试过的。到目前为止没有运气。这是我的代码
jQuery
$(document).on('keyup change','.unit_price',function(){
var tr = $(this).parents('tr');
var price = $(this).val();
price = parseInt(price);
var rownumber = $('#protable').index(tr);
alert(rownumber);
}
HTML
<table id ="protable">
<tr>
<th>Is Ordered</th>
<th>Check List Item</th>
<th>Qty</th>
<th>Unit</th>
<th>Supplier</th>
<th>Unit Price</th>
<th>Total Price</th>
<th>Remarks</th>
</tr>
</table>
我的目标是通过乘以单价和数量来自动计算总价。请帮帮我
答案 0 :(得分:0)
好吧,我终于明白了。实际上,这非常简单。
$(document).on('keyup change','.unit_price',function(){
var tr = $(this).parents('tr');
var price = $(this).val();
price = parseInt(price);
var rownumber = tr.index();
}