如下所示,可以输入amount
和fee-rate
字段,但fee
会自动设置(fee=rate*amount
),因此人们不会计算它他们自己。
<div class="loanr" id="loan-rate"><?= $form->field($model, 'amount')?></div>
<div class="loanr" id="loan-rate"><?= $form->field($model, 'fee-rate')?></div>
如何更改此行:
<div class="loanr" id="loan-fee"><?= $form->field($model, 'fee')?></div>
我可以使用ajax
,但我不知道如何以Yii
形式填写此内容。
答案 0 :(得分:1)
在视图中输入此代码:
<?php
$this->registerJs("$('#rate, #amount').keyup(function(){
var rate = $('#rate').val(),
amount = $('#amount').val(),
fee = 0;
rate = rate - 0;//convert to integer
amount = amount - 0;//convert to integer
fee = rate * amount;
$('#fee').val(fee);
});");
?>
并形成:
<div class="loanr" id="loan-rate"><?= $form->field($model, 'amount')->textInput(['id' => 'amount'])?></div>
<div class="loanr" id="loan-rate"><?= $form->field($model, 'fee-rate')->textInput(['id' => 'rate'])?></div>
<div class="loanr" id="loan-fee"><?= $form->field($model, 'fee')->textInput(['id' => 'fee'])?></div>