簡體   English   中英

如何在keyup事件上使用Jquery獲取動態生成的表的單元格的行索引號?

[英]How to get the row index number of the cell of a dynamically generated table using Jquery on keyup event?

我有一個使用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>

我的目標是通過乘以單價和數量自動計算總價。 請幫幫我

好的,我終於明白了。 實際上非常簡單。

$(document).on('keyup change','.unit_price',function(){
    var tr = $(this).parents('tr');
    var price = $(this).val();          
    price = parseInt(price);
    var rownumber = tr.index();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM