Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用javascript计算数组表单的和_Javascript_Jquery_Html_Calculator_Dynamic Forms - Fatal编程技术网

用javascript计算数组表单的和

用javascript计算数组表单的和,javascript,jquery,html,calculator,dynamic-forms,Javascript,Jquery,Html,Calculator,Dynamic Forms,我想显示值的数量​​以数组形式。我有很多表单,只有一个名称是“price[]”,表单上有每个值。我想计算表单“price[]”的总值。我还是javascript的初学者。我想用javascript计算它。下面是我编写的代码 <html> <body> <form id="hitung" name="hitung"> price 1 <input type="text" name="price[]" clas

我想显示值的数量​​以数组形式。我有很多表单,只有一个名称是“price[]”,表单上有每个值。我想计算表单“price[]”的总值。我还是javascript的初学者。我想用javascript计算它。下面是我编写的代码

<html>
    <body>
        <form id="hitung" name="hitung">
            price 1 <input type="text" name="price[]" class="price" value="1000"/><br>
            price 2 <input type="text" name="price[]" class="price" value="3000"/><br>
            price 3 <input type="text" name="price[]" class="price" value="2000"/><br>
            price 4 <input type="text" name="price[]" class="price" value="1000"/><br>
            price 5 <input type="text" name="price[]" class="price" value="3000"/><br><br>
            total <input type="text" name="total" class="total"/>
        </form>
    </body>
</html>

价格1
价格2
价格3
价格4
价格5

全部的
我想再次问你,如果有来自外部的新输入,那么总数也会直接改变。怎么做。请帮帮我。谢谢你这里有一个例子:


你不需要一个数量来配合价格吗?
var sum = 0;
$("form > input[name='price[]']").each(function() {
    $this = $(this);
    sum += parseInt($this.attr("value"));
});
$("form > input[name='total']").attr("value", sum);