计算另一个计算百分比的Javascript [英] Javascript that calculates % of another calculation

查看:101
本文介绍了计算另一个计算百分比的Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码计算输入数字的8%,例如在下面的代码中。如果您在第一个框中输入1并在第二个框中输入100,则总退款(包括8%)= 108



JavaScript代码:



I have code which calculates 8% of the number entered, so for example is in the code below. If you enter "1" in the first box" and "100" in the second box the Total Refund (including 8%) = 108

JavaScript code:

$(document).ready(function() {
var sum = 0;
function calcSum(prevVal) {
var val1 = $('#val1').val();
var val2 = $('#val2').val();
var val3 = $('#val3').val();
var val4 = $('#val4').val();
this.sum = parseFloat(val1) * parseFloat(val2) + parseFloat(val3) * parseFloat(val4);
return this.sum;
}
var subAmt = $("#sub"),
taxAmt = $("#tax"),
totAmt = $("#total");
$(".val").each(function() {
var prevVal = this.value / 1,
self = this;
$(this).keyup(function() {
subAmt.val(calcSum.call(self, prevVal));
totAmt.val(this.sum + this.sum * parseFloat(taxAmt.val() / 100));
prevVal = self.value; 
});
});
});





http://jsfiddle.net/2k1zr59u/3/



我想做的是计算底部框中第二个8%的20%。所以在这个例子中答案应该是1.60。



然后我想在总框106.40(108 - 1.60)中显示。



http://jsfiddle.net/2k1zr59u/3/

What I would like to do is to calculate 20% of the 8% in the second to the bottom box. So in this example the answer should be 1.60.

Then I would like to show in the total box 106.40 (108 - 1.60).

推荐答案

document )。ready( function (){
var sum = 0 ;
function calcSum(prevVal){
var val1 =
(document).ready(function() { var sum = 0; function calcSum(prevVal) { var val1 =


' #val1')。val();
var val2 =
('#val1').val(); var val2 =


' #val2')。val() ;
var val3 =
('#val2').val(); var val3 =


这篇关于计算另一个计算百分比的Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆