我对编程很陌生,所以如果不是最好的问题请原谅!
我正在尝试使用jquery.calculation.js插件创建一个计算器。到目前为止,我可以输入人1的基本工资和人2的基本工资,然后显示基本工资。然后它允许您输入每个人的季度奖金,并且当前显示它确定为“实际季度”奖励(这是用户输入的x 0.6)
我感到困惑的是,我需要它来计算人1的实际季度和基本收入,然后对人2做同样的事情,并将这些值输出到表中的grand_total1和grandtotal2行,但无论我做什么我无法做到这一点。这是我到目前为止所拥有的。有什么想法吗?
感谢。
<script type="text/javascript" src="jquery.field.min.js"></script>
<script type="text/javascript" src="jquery.calculation.js"></script>
<script type="text/javascript">
var bIsFirebugReady = (!!window.console && !!window.console.log);
$(document).ready(
function (){
// update the plug-in version
$("#idPluginVersion").text($.Calculation.version);
/*
$.Calculation.setDefaults({
onParseError: function(){
this.css("backgroundColor", "#cc0000")
}
, onParseClear: function (){
this.css("backgroundColor", "");
}
});
*/
// bind the recalc function to the fields
$("input[name^=quarterly_bonus_]").bind("keyup", recalc);
$("input[name^=basic_salary_]").bind("keyup", recalc);
// run the calculation function now
recalc();
}
);
function recalc(){
$("[id^=actual_quarterly_]").calc(
// the equation to use for the calculation
"statedquarterly * factor",
{
statedquarterly: $("input[name^=quarterly_bonus_]"),
factor: 0.6
},
function (s){
// return the number as a dollar amount
return "£" + s.toFixed(2);
},
function ($this){
// sum the total of the $("[id^=total_item]") selector
var sum1 = $this.sum();
$("#grandTotal").text(
// round the results to 2 digits
"£" + sum1.toFixed(2)
);
}
);
$("[id^=actual_basic_]").calc(
// the equation to use for the calculation
"qty",
{
qty: $("input[name^=basic_salary_]")
},
function (s){
// return the number as a dollar amount
return "£" + s.toFixed(2);
},
function ($this){
// sum the total of the $("[id^=total_item]") selector
var sum = $this.sum();
$("#grandTotal2").text(
// round the results to 2 digits
"£" + sum.toFixed(2)
);
}
);
}
</script>
<table width=1000" style="font-size:1em;">
<col style="width: 150px;" />
<col style="width: 150px;" />
<col style="width: 150px;" />
<col style="width: 150px;" />
<col style="width: 150px;" />
<col style="width: 150px;" />
<tr>
<th style="font-size:0.9em;"
</th>
<th style="font-size:0.9em;">
Insert Figures into this column
</th>
<th style="font-size:0.9em;">
Applicant 1
</th>
<th style="font-size:0.9em;">
Insert Figures into this column
</th>
<th style="font-size:0.9em;">
Applicant 2
</th>
</tr>
<tr>
<td>Basic Salary (annual value)</td>
<td align="center">
<input type="text" name="basic_salary_1" id="basic_salary_1" value="0" size="5" />
</td>
<td align="center" id="actual_basic_1">
--
</td>
<td align="center">
<input type="text" name="basic_salary_2" id="basic_salary_2" value="0" size="5" />
</td>
<td align="center" id="actual_basic_2">
--
</td>
</tr>
<tr>
<td>Quarterly Bonus (annual value)</td>
<td align="center">
<input type="text" name="quarterly_bonus_1" id="quartlery_bonus_1"
value="0" size="5" />
</td>
<td align="center" id="actual_quarterly_1">
--
</td>
<td align="center">
<input type="text"
name="quarterly_bonus_2" id="quarterly_bonus_2"
value="0" size="5" />
</td>
<td align="center" id="actual_quarterly_2">
--
</td>
</tr>
<tr>
<td colspan="2" align="right">
<strong>Grand Total 1:</strong>
</td>
<td align="center" id="grandTotal1">
</td>
<td colspan="1" align="right">
<strong>Grand Total 2:</strong>
</td>
<td align="center" id="grandTotal2">
</td>
</tr>
</table>