我想在加载页面后自动计算贷款支付。对于付款计算,我有javascript函数calculatePayment(field.form)
。
我有四个变量,可以由用户更改。默认情况下,我将使用当前帖子中的信息(例如汽车价格,5.5%利息,5年,汽车价格10%首付):
<p><label class="loan-title" for="l-amount"><?php _e('PRICE: '.$symbols['currency'].'','language')?></label>
<input type="text" size="10" name="price" value="<?php if ( $fields['price']){ echo $fields['price'];} else { echo '0'; };?>" class="l-inputbar" id="l-amount" onBlur="checkForZero(this)" onChange="checkForZero(this)"></p>
<p><label class="loan-title" for="l-down"><?php _e('DOWNPAYMENT: '.$symbols['currency'].'','language')?></label>
<input type="text" size="10" name="dp" id="l-down" class="l-inputbar" value="<?php if ( $fields['price']){ echo $fields['price']*0.1;} else { echo '0'; };?>" onChange="calculatePayment(this.form)"></p>
<p><label class="loan-title" for="l-amount"><?php _e('PROCENTU LIKME: %','language')?></label>
<input type="text" size="5" name="ir" value="5.5" class="l-inputbar" onBlur="checkForZero(this)" onChange="checkForZero(this)"> </p>
<p><label class="loan-title" for="l-amount"><?php _e('PERIOD: (years) ','language')?></label>
<input type="text" size="4" name="term" value="5" class="l-inputbar" onBlur="checkForZero(this)" onChange="checkForZero(this)"> </p>
<p class="calculate-wrapper"><input type="button" name="cmdCalc" value="" class="calculate-btn" onClick="cmdCalc_Click(this.form)" onLoad="calculatePayment(this.form)" ></p>
<p><label class="loan-title" for="l-amount"><?php _e('MONTHLY PAYMENT: '.$symbols['currency'].'','language')?></label>
<input type="label" size="12" class="l-inputbar" name="pmt"></p>
所有数据都加载到输入字段中,但我找不到解决方案如何计算页面加载时的付款。我已经尝试了所有的javascript函数调用。似乎没什么用。
答案 0 :(得分:1)
您可以使用jQuery的 document.ready()或* $(function(){/ *这里的东西* /})*来检查文档是否已加载和呈现。它比 window.onload 复杂一点,所以我建议你使用一个框架(无论如何)。