我正在尝试创建一个表单,我可以根据两个输入计算两个区域的平均值。那么我想平均我的两个计算平均值(支付给高补偿EE的平均收益/支付给非高补偿EE的平均收益)。在此计算过程中,我的代码onkeyup在某处被破坏了。最后,我想为id =" TestResult"执行IF语句。如果(支付给高度补偿的EE的平均福利金/支付给非高度补偿的EE的平均福利金)> = 55%那么" Pass"否则"失败"。我是java的新手,所以我可以真正使用帮助来修复我的代码,并使这个IF语句正常工作。有什么建议?
<script language="JavaScript">
$(document).ready(function() {
$(".input").keyup(function() {
var val1 = +$(".value1").val();
var val2 = +$(".value2").val();
$("#result").val(val1 / val2);
var val3 = +$(".value3").val();
var val4 = +$(".value4").val();
$("#result2").val((val3/val4));
$("#result3").val(((val3+val4)/(val1+val2))*100);
});
});
<table>
<tr>
<td>Non-taxable benefits paid to Highly Compensated EE's:</td>
<td>
<input type="text" class="input value1">
</td>
</tr>
<tr>
<td>Number of Highly Compensated Employees:</td>
<td>
<input type="text" class="input value2">
</td>
</tr>
<tr>
<td>Average Benefits paid to Highly Compensated EE's:</td>
<td>
<input type="text" disabled="disabled" id="result">
</td>
</tr>
<tr>
<td>Non-taxable benefits paid to Non-Highly Compensated EE's:</td>
<td>
<input type="text" class="input value3">
</td>
</tr>
<tr>
<td>Number of Non-Highly Compensated Employees included*:</td>
<td>
<input type="text" class="input value4">
</td>
</tr>
<tr>
<td>Average Benefits paid to Non-Highly Compensated EE's:</td>
<td>
<input type="text" disabled="disabled" id="result2">
</td>
</tr>
<tr>
<td>Average Benefit Percentage Ratio:</td>
<td>
<input type="text" disabled="disabled" id="result3">
</td>
</tr>
<tr>
<td>Result:</td>
<td>
<input type="text" id="TestResult" style='overflow:hidden; border:0px solid #000000; width:80%'>
</td>
</tr>
答案 0 :(得分:0)
$(document).ready(function() {
$(".input").keyup(function() {
var val1 = +$(".value1").val();
var val2 = +$(".value2").val();
$("#result").val((val1 / val2).toFixed(2));
var val3 = +$(".value3").val();
var val4 = +$(".value4").val();
$("#result2").val((val3/val4).toFixed(2));
$("#result3").val(((val3+val4)/(val1+val2)*100).toFixed(2) + "%");
var result = $("#result").val()/$("#result2").val();
if(result >= 0.55){
$("#TestResult").val((result * 100).toFixed(2) + "%" + "Pass");
} else {
$("#TestResult").val("FAIL");
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table>
<tr>
<td>Non-taxable benefits paid to Highly Compensated EE's:</td>
<td>
<input type="text" class="input value1">
</td>
</tr>
<tr>
<td>Number of Highly Compensated Employees:</td>
<td>
<input type="text" class="input value2">
</td>
</tr>
<tr>
<td>Average Benefits paid to Highly Compensated EE's:</td>
<td>
<input type="text" disabled="disabled" id="result">
</td>
</tr>
<tr>
<td>Non-taxable benefits paid to Non-Highly Compensated EE's:</td>
<td>
<input type="text" class="input value3">
</td>
</tr>
<tr>
<td>Number of Non-Highly Compensated Employees included*:</td>
<td>
<input type="text" class="input value4">
</td>
</tr>
<tr>
<td>Average Benefits paid to Non-Highly Compensated EE's:</td>
<td>
<input type="text" disabled="disabled" id="result2">
</td>
</tr>
<tr>
<td>Average Benefit Percentage Ratio:</td>
<td>
<input type="text" disabled="disabled" id="result3">
</td>
</tr>
<tr>
<td>Result:</td>
<td>
<input type="text" id="TestResult" style='overflow:hidden; border:0px solid #000000; width:80%'>
</td>
</tr>
</table>