Price、Quantity、および Total の 3 つの入力要素の行で構成されるテーブルがあります。その下には、テーブルに別の行を動的に生成するためにクリックできる 2 つのリンクがあります。すべてうまく機能していますが、実際に合計要素の値を計算すると問題が発生します。最初の合計要素の値を計算する方法は知っていますが、テーブルに新しい行を追加するときにこの機能を拡張するのに問題があります。html は次のとおりです。
<table id="table" border="0">
<thead>
<th>Price</th><th>Quantity</th><th>Total</th>
</thead>
<tbody>
<tr>
<td><input id ="price" type = "text"></input></td>
<td><input id ="quantity" type = "text"></input></td>
<td><input id ="total" type = "text"></input></td>
</tr>
</tbody>
</table>
<a href="#" id="add">Add New</a>
<a href="#" id="remove">Remove</a>
私が使用しているjqueryは次のとおりです。
$(function(){
$('a#add').click(function(){
$('#table > tbody').append('<tr><td><input id ="price" type = "text"></input></td><td><input id ="quantity" type = "text"></input></td><td><input id ="total" type = "text"></input></td></tr>');
});
$('a#remove').click(function(){
$('#table > tbody > tr:last').remove();
});
});
$(function(){
$('a#calc').click(function(){
var q = $('input#quantity').val();
var p = $('input#price').val();
var tot = (q*p);
$('input#total').val(tot);
});
});
私はjqueryを初めて使用するので、計算したい関連フィールドを選択する簡単な方法がわからない可能性があります。ガイダンスをいただければ幸いです。