我正在使用jquery减去两个类值创建html页面多输入值记录显示。请帮帮我
HTML
<tr>
<td><input type="hidden" name="quarter_no[]" value="<?=$value->quarter_no?>">Quarter <?=$value->quarter_no?></td>
<td colspan="4"><input type="text" class="form-control" name="receipt_no[]" value="<?=$value->receipt_no?>" placeholder="Quarter1 Recept No."></td>
<td><input type="text" class="form-control credited" id="quarter1_amtPaid" name="amount_credited[]" value="<?=$value->amount_credited?>" placeholder="0.00"></td>
<td><input type="text" class="form-control deducted" id="quarter1_taxDeducted" name="amount_tax_deduction[]" value="<?=$value->amount_tax_deducted?>" placeholder="0.00"></td>
<td><input type="text" class="form-control remitted" id="quarter1_taxRemitted" name="amount_tax_remitted[]" value="<?=$value->amount_tax_remitted?>" placeholder="0.00"></td>
jquery的
$(document).ready(function(){
$("body").on("blur", ".credited, .deducted", function(){
var arr = document.getElementsByName('amount_credited[]');
var tot=0;
for(var i=0;i<arr.length;i++){
if(parseInt(arr[i].value))
tot += parseInt(arr[i].value);
}
document.getElementById('quarter1_taxRemitted').value = tot;
});
})
答案 0 :(得分:0)
<script>
$(document).ready(function () {
$(".credited , .deducted").on("blur", function () {
console.log($('#quarter1_amtPaid').val());
var paid = $('#quarter1_amtPaid').val();
var Deducted = $('#quarter1_taxDeducted').val();
var tot = parseFloat(paid) - parseFloat(Deducted);
$('#quarter1_taxDeducted').val(tot);
});
})
</script>
尝试这个。