我已經創建了一個動態表,其中生成了多行,並且在每行內部我都有一個模態和形式包含在模態中。每個模態形式都有唯一的ID。現在我想在禁用的文本字段中顯示兩個變量的結果。那麼,我該怎麼做?請幫助我。如果動態生成多行,如何在jQuery中添加兩個變量?
$(document).ready(function(){
var a = parseInt($('#unit_rate'+this.id).val());
var b = parseInt($('#tax'+this.id).val());
var total = a+b;
$('#price').val(total);
});
<input type="text" name="unit_rate" id="unit_rate<?php echo $product_id; ?>" value="">
<input type="text" name="tax" id="tax<?php echo $product_id; ?>" value="">
<input type="text" name="price" id="price<?php echo $product_id; ?>" value="">
謝謝
在使用this.id中定義「id」的地方 –
問題是'this.id'是'undefined'。 – George
鑑於'this'是指'window',你期待'this.id'返回什麼? –