简体   繁体   English

在同一网页上的不同场合需要一个简单的数值差(+/-)脚本

[英]Need a simple numerical value difference(+/-) script for different occasions on the same web page

I authored a web page/form utilizing a chart script(AMcharts) which involves inputs of many numerical values in order to make a graph. 我编写了一个使用图表脚本(AMcharts)的网页/表单,该脚本涉及许多数字值的输入以便制作图形。 Built into this web page is a separate average script utilized many times in order to get many successive average values, as well as a simple numerical difference script for the last two/three of the final average values. 内置在此网页中的是一个单独的平均脚本,该脚本多次使用以获取许多连续的平均值,以及一个用于最后两个/三个最终平均值的简单数值差异脚本。 Basically, when all averages are parsed, a value from a previous occasion is typed in an input field, and the script instantly displays a difference, either + or -. 基本上,当解析所有平均值时,会在输入字段中键入前一次情况的值,并且脚本会立即显示差异,即+或-。 The average value script I managed to manipulate for 16 occasions (much to my surprise). 我设法处理了16次平均值脚本(令我惊讶的是)。 I am, however, having problems manipulating the numerical difference script in order to display more than one value difference set. 但是,我在处理数值差异脚本以显示多个值差异集时遇到问题。 The simple script found below is utilized successfully, however I need to know how to manipulate it for more than just that one occasion. 下面找到的简单脚本已被成功利用,但是我需要知道如何操作它不止一次。

$(function(){           
    $('input').each(function() {
        $(this).keyup(function(){  
            calculateTotal($(this));
        });
    });
});

function calculateTotal(src) {
    var sum = 0;
    var sumtable = src.closest('.sumtable');

    sumtable.find('input').each(function() {
        if(!isNaN(this.value) && this.value.length!=0) {
            sum += parseFloat(this.value);
        }
    });

    sumtable.find(".total").html(sum.toFixed(2));
    var balance = parseFloat($('.actual').val()) - sum
    sumtable.find(".balance").html(balance.toFixed(2));
}  

I need the following code repeated for different value fields, independent of the other(s): 我需要针对不同的值字段(与其他值无关)重复以下代码:

http://jsfiddle.net/ZZX5D/ http://jsfiddle.net/ZZX5D/

The following link takes you to my work in progress. 以下链接将带您进入我正在进行的工作。 To make it work(not the graph, but the numerical scripts), type in random values for the first four empty fields- B1 PS/CS - B2 PS/CS and under "battery 2" fill in the first 4 empty fields. 要使其工作(不是图形,而是数字脚本),请为前四个空白字段(B1 PS / CS-B2 PS / CS)输入随机值,并在“电池2”下填写前四个空白字段。 Then in the above averaged displays, simply click inside all fields with a numerical value and press "enter", and continue doing so until all fields are automatically displayed. 然后,在以上平均显示中,只需在所有带有数字值的字段内单击,然后按“输入”,然后继续这样做,直到自动显示所有字段。 Then, under "previous" fields, type another random number. 然后,在“上一个”字段下,键入另一个随机数。 The first field "difference" is correct. 第一个字段“差异”是正确的。 The remaining two display the difference between that number and the initial "overall" instead of the last average values to their immediate left. 其余两个显示该数字和初始“总和”之间的差,而不是最后一个平均值到它们的最左边。

http://dcalvitti.altervista.org/AVGSAMPLE.html http://dcalvitti.altervista.org/AVGSAMPLE.html

Never solved this, but found an alternate script that was easy to manipulate and thus serve my purposes. 从来没有解决过这个问题,而是找到了一个易于操作的备用脚本,因此可以满足我的目的。

http://www.codingfriends.com/index.php/2009/07/27/add-two-numbers-3/ http://www.codingfriends.com/index.php/2009/07/27/add-two-numbers-3/

And the chart incorporating this solution can be found at this page: 可以在此页面上找到包含此解决方案的图表:

http://dcalvitti.webs.com/SAMPLE/NEWWEBINDEX.html http://dcalvitti.webs.com/SAMPLE/NEWWEBINDEX.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM