将税收计算添加到jQuery计算插件

我正在使用这里找到的非常有用的jQuery Calulation插件,

http://www.pengoworks.com/workshop/jquery/calculation/calculation.plugin.htm

我用它来计算报价表格的行项目总数和子总数。 我有它工作,以便它计算单个行项目和小计。 我的下一个要求是添加税额,最后是总计。 这就是我的jQueryfunction已经结束的地方。 我尝试过一些东西,但最终却破坏了一切。 税额是固定的,所以我需要做的是取小计并用它来计算税额,然后将税额加到小计中以创建总额。

到目前为止我有这个脚本,

  var bIsFirebugReady = (!!window.console && !!window.console.log); $(document).ready( function (){ // bind the recalc function to the quantity fields $("input[id^=q]").bind("keyup", recalc); $("input[id^=p]").bind("keyup", recalc); // run the calculation function now recalc(); // automatically update the "#totalSum" field every time // the values are changes via the keyup event $("input[name^=sum]").sum("keyup", "#totalSum"); // this calculates the sum for some text nodes $("#idTotalTextSum").click( function (){ // get the sum of the elements var sum = $(".textSum").sum(); // update the total $("#totalTextSum").text("€" + sum.toString()); } ); // this calculates the average for some text nodes $("#idTotalTextAvg").click( function (){ // get the average of the elements var avg = $(".textAvg").avg(); // update the total $("#totalTextAvg").text(avg.toString()); } ); } ); function recalc(){ $("[id^=total_item]").calc( // the equation to use for the calculation "qty * price", // define the variables used in the equation, these can be a jQuery object { qty: $("input[id^=q]"), price: $("input[id^=p]") }, // define the formatting callback, the results of the calculation are passed to this function function (s){ // return the number as a dollar amount return "€" + s.toFixed(2); }, // define the finish callback, this runs after the calculation has been complete function ($this){ // sum the total of the $("[id^=total_item]") selector var sum = $this.sum(); $("#myTotal").val( // round the results to 2 digits "€" + sum.toFixed(2) ); } ); }  

这是HTML的片段,

    (none) Tasks Resources Expenses Other                 (none) Tasks Resources Expenses Other               Subtotal     Tax (19.6%)    Total   

如果有人能够帮助它将非常感激。

非常感谢

克里斯

更改HTML的税务部分:

  Tax (19.6%)              

并将此函数添加到脚本:

 function Compute() { var Total = document.getElementById("myTotal").value; var Tax = document.getElementById("tax").value; var NewTotal = document.getElementById("newTotal"); var TaxAmount = document.getElementById("taxAmount"); Total = parseFloat(Total); Tax = parseFloat(Tax); TaxAmount.value = Math.max((Total * Tax) / 100).toFixed(2) + "" NewTotal.value = Math.max(Total + (Total * Tax) / 100).toFixed(2) + ""; } 

如果您收到NaN结果,请从脚本和输入值中删除“€”符号。