我正在使用js计算2个值:
$('input').keyup(function(){ // run anytime the value changes
var firstValue = Number($('#user_send_fund_amount').val());
var secondValue = Number($('#fixed_amount').val());
document.getElementById('user_receive_fund_amount').value = firstValue * secondValue ;});
并尝试存储此值:
<form method="POST" class="form-register" action="{{ route('order.store') }}">
@csrf
<input id="user_send_fund_amount" type="number" class="form-control"
name="user_send_fund_amount" required>
<input type="number" value="{{$receive->buy}}" class="form-control"
id="fixed_amount" hidden>
<input type="number" class="form-control" id="user_receive_fund_amount" name="user_receive_fund_amount" readonly/>
</form>
您的代码在此行中有语法错误:
document.getElementById('user_receive_fund_amount').value = firstValue * secondValue ;});
从末尾删除;})
。因此,该行变为:
document.getElementById('user_receive_fund_amount').value = firstValue * secondValue;