Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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
Jquery 更新总金额的总和_Jquery_Jquery Ui - Fatal编程技术网

Jquery 更新总金额的总和

Jquery 更新总金额的总和,jquery,jquery-ui,Jquery,Jquery Ui,我想更新总和框中的自动总和 自动更新总和框中总列的总和 这将如何工作,这是我的代码 JS小提琴在这里: 以下是HTML: <table id="items"> <thead> <th>Unit</th> <th>Qty</th> <th>Total</th> </thead> <tbody>

我想更新总和框中的自动总和

自动更新总和框中总列的总和

这将如何工作,这是我的代码

JS小提琴在这里:

以下是HTML:

<table id="items">
    <thead>
        <th>Unit</th>
        <th>Qty</th>
        <th>Total</th>
    </thead>
    <tbody>
        <tr>
            <td><input class="input3 unit" name="unit_1" type="text" value=""></td>
            <td><input class="input3 qty" name="qty_1" type="text" value=""></td>
            <td><input class="input3 total" name="total_1" type="text" value=""></td>
        </tr>
        <tr>
            <td><input class="input3 unit" name="unit_1" type="text" value="" autocomplete="off"></td>
            <td><input class="input3 qty" name="qty_1" type="text" value="" autocomplete="off"></td>
            <td><input class="input3 total" name="total_1" type="text" value="" autocomplete="off"></td>
        </tr>
    </tbody>
</table>

<br clear="both">

<table id="items">
    <thead>
        <th>Sum</th>
    </thead>
    <tbody>
        <tr>
            <td><input class="input3 sum" name="sum" type="text" value="" autocomplete="off"></td>
       </tr>
    </tbody>
</table>

类似这样的方法会奏效:

var sum=0;
$('.total').each(function(index){sum+=( parseFloat($(this).val()) || 0); }) ;
// get total amount
$('.sum').val(sum );

类似的方法会奏效:

var sum=0;
$('.total').each(function(index){sum+=( parseFloat($(this).val()) || 0); }) ;
// get total amount
$('.sum').val(sum );

我添加到您的小提琴中,您可以使用.each函数将最后一列相加

$(".total").each(function(index,item){...});

这里的Fiddle:

我添加到您的Fiddle中,您可以使用.each函数合计最后一列

$(".total").each(function(index,item){...});

在这里摆弄:

您需要添加一些逻辑来保持一个运行总数。下面是一个解决方案的分叉:


您需要添加一些逻辑来保持总数。下面是一个解决方案的分叉:


当单位数量发生变化时,最好触发更新<代码>$('.qty.unit').keyup(函数(e).如果单位金额也在更改,则最好触发更新。
$('.qty.unit').keyup(函数(e).