Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.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
Php 表jquery中元素的总和_Php_Jquery_Mysql - Fatal编程技术网

Php 表jquery中元素的总和

Php 表jquery中元素的总和,php,jquery,mysql,Php,Jquery,Mysql,我有一个php文件,可以创建这样的表 <table style="text-align:center; margin-top:20px;" align="center" cellpadding="5"> <caption><u><b>Ordine del 22-10-2015 delle ore 16:08:38<b/></u><br /></caption> <thead style="b

我有一个php文件,可以创建这样的表

<table style="text-align:center; margin-top:20px;" align="center" cellpadding="5"> 
<caption><u><b>Ordine del 22-10-2015 delle ore 16:08:38<b/></u><br /></caption> 
<thead style="background-color:#EBE9E9"> 
<tr> 
    <th scope="col">Prodotto</th> 
    <th scope="col">Quantit&agrave;</th> 
    <th scope="col">Prezzo</th> 
    <th scope="col">Totale parziale</th> 
</tr> 
</thead> 
<tbody style="background-color:F5FFFF"> 
<tr> 
    <td>Coca Cola</td> 
    <td> x1</td> 
    <td>1,50 &euro;</td> 
    <td>1,50 &euro;</td> 
    <td><input type="hidden" class="toadd" value="1.50"></td>
</tr><tr> 
    <td>Limonata</td> 
    <td> x1</td> 
    <td>1,50 &euro;</td> 
    <td>1,50 &euro;</td> 
        <td><input class="toadd" type="hidden" value="1.50"></td>
    </tr><tr> 
    <td>Maxibon</td> 
    <td> x1</td> 
    <td>2,00 &euro;</td> 
    <td>2,00 &euro;</td> 
        <td><input class="toadd" type="hidden" value="1.50"></td>
    </tr><tr> 
    <td>Pirulo</td> 
    <td> x1</td> 
    <td>1,00 &euro;</td> 
    <td>1,00 &euro;</td> 
    <td><input class="toadd" type="hidden" value="1.50"></td>
    </tr>
    <tr>
    <td colspan="2">Totale</td>
    <td colspan="2" class="totale"></td>
    </tr>
    </tbody></table> 
问题是,当只有一个表时,它工作得很完美,但当表不止一个时,它会给出所有表的总和


我只需要每个表的总数

尝试迭代所有表并遍历每个表元素以计算/设置值

$("table").each(function(){
   $('.toadd', this).each(function() {
     sum += Number($(this).val());
   });
  $('.totale', this).text(sum.toLocaleString('it-IT', {
    style: 'currency', 
    currency: 'EUR', 
    minimumFractionDigits: 2 
  }));
});
$("table").each(function(){
   $('.toadd', this).each(function() {
     sum += Number($(this).val());
   });
  $('.totale', this).text(sum.toLocaleString('it-IT', {
    style: 'currency', 
    currency: 'EUR', 
    minimumFractionDigits: 2 
  }));
});