我正在尝试创建一个动态表单,每次更改 4 个输入字段之一时重新计算值。至今..
<script type="text/javascript"><!--//--><![CDATA[//><!--
jQuery(document).ready(function(jQuery){ ...variables...
然后我有..
jQuery('.changeCalc').change(function()
{
calculations();
});
我正在使用更改功能来重新执行我创建的计算功能。问题是,当我对此进行测试时,我更改了四个字段中的任何一个字段并执行该calculations()
功能。问题:每次页面加载它只执行一次。是否可以更改它以使其多次触发?
相关HTML:
<input type="text" name="managed_properties" id="managed_properties" class="changeCalc" required />
<input type="text" name="inspections_peryr" id="inspections_peryr" value="" class="changeCalc" required />
<select name="time_reports" id="time_reports" class="changeCalc" required>
<option value="20">20 minutes</option>
<option value="30">30 minutes</option>
<option value="45">45 minutes</option>
<option value="1">1 hour</option>
<option value="2">2 hours</option>
</select>
<select name="prop_managers" id="prop_managers" class="changeCalc" required>
<option value="15">$15</option>
<option value="20">$20</option>
<option value="25">$25</option>
<option value="30">$30</option>
<option value="40">$40</option>
<option value="50">$50</option>
</select>
编辑:到目前为止的答案还没有奏效,所以也许显示计算函数可以阐明这里的真正问题..
calculations = function()
{
//Perform the calculations
if (noProp != null && noTimesInsp != null && timeCompile != null && rateManager != null)
{
// Step 2 per year
saveHrYr = timeCompile * (noProp * noTimesInsp);
saveDollarYr = ((rateManager * (timeCompile * (noProp * noTimesInsp))) * (noProp * .17))
ROI = ((rateManager * (timeCompile * (noProp * noTimesInsp))) / ((noProp * .17)*12))
//Display the answer
var displaySaveHrYr = document.getElementById('snapSvHrYr');
jQuery('#snapSvHrYr').empty();
displaySaveHrYr.innerHTML = displaySaveHrYr.innerHTML + saveHrYr.toFixed(0);
var displaySaveDollarYr = document.getElementById('snapSvDollarYr');
jQuery('#snapSvDollarYr').empty();
displaySaveDollarYr.innerHTML = displaySaveDollarYr.innerHTML + saveDollarYr.toFixed(0);
var displayROI = document.getElementById('backPerDollar');
jQuery('#backPerDollar').empty();
displayROI.innerHTML = displayROI.innerHTML + ROI.toFixed(0);
// Step 2 per month
saveHrMth = (timeCompile * (noProp * noTimesInsp)/12);
saveDollarMth = ((rateManager * (timeCompile * (noProp * noTimesInsp))) * (noProp * .17))/12
var displaySaveHrMth = document.getElementById('snapSvHrMth');
jQuery('#snapSvHrMth').empty();
displaySaveHrMth.innerHTML = displaySaveHrMth.innerHTML + saveHrMth.toFixed(0);
var displaySaveDollarMth = document.getElementById('snapSvDollarMth');
jQuery('#snapSvDollarMth').empty();
displaySaveDollarMth.innerHTML = displaySaveDollarMth.innerHTML + saveDollarMth.toFixed(0);
//SnapInspect cost per yr/mth
snapCostMth = noProp * .17
snapCostYr = snapCostMth * 12
var displaySnapCostYr = document.getElementById('snapCostYr');
jQuery('#snapCostYr').empty();
displaySnapCostYr.innerHTML = displaySnapCostYr.innerHTML + snapCostYr.toFixed(0);
var displaySnapCostMth = document.getElementById('snapCostMth');
jQuery('#snapCostMth').empty();
displaySnapCostMth.innerHTML = displaySnapCostMth.innerHTML + snapCostMth.toFixed(0);
}
};