我有两个方框,一个名为AuthorizedAmount
,另一个名为LessLaborToDate
:
<div class="col-md-6">
<div class="form-group">
<label>Authorized Amount</label>
<div class="input-group">
<span class="input-group-addon">$</span>
<input type="number" class="form-control" name="AuthorizedAmount" min=0 step="0.01" required>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Less Labor to Date</label>
<div class="input-group">
<span class="input-group-addon">$</span>
<input type="number" class="form-control" name="LessLaborToDate" min=0 step="0.01" required>
</div>
</div>
</div>
如何将这两个值自动汇总到另一个框中,名为小计?
<div class="col-md-6">
<div class="form-group">
<label>Subtotal</label>
<div class="input-group">
<span class="input-group-addon">$</span>
<input type="number" class="form-control" name="Subtotal" placeholder="Authorized Amount minus Less Labor to Date" min=0 step="0.01" readonly>
</div>
</div>
</div>
答案 0 :(得分:1)
使用jquery,类似这样:
$("input[name='AuthorizedAmount'], input[name='LessLaborToDate']").change(function() {
var sum = $("input[name='AuthorizedAmount']").val() + $("input[name='LessLaborToDate']").val();
$("input[name='Subtotal']").val(sum);
});
您可能需要添加一些空检查和parseInt
,但您会明白我希望