php/mysqlでループを使用して、構造は同じですが値が異なる倍数テーブルを生成します。私はすべての値を合計して結果を表示するスクリプトを持っていますが、値が同じ行にある場合にのみ動作します。私は "precio"列だけを合計する必要があります。JQueryを使用して複数のテーブルの合計を得るための合計の列数
ここはHTMLです。これは、テーブルの構造です:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('tr').each(function() {
var sum = 0
$(this).find('.precio').each(function() {
var precio = $(this).text();
if (!isNaN(precio) && precio.length !== 0) {
sum += parseFloat(precio);
}
});
$('.total_prt', this).html(sum);
});
});
</script>
<table class="table table-striped">
<thead>
<tr>
<th width="70%">Descripción</th>
<th width="20%">Precio</th>
</tr>
</thead>
<tbody>
<tr>
<td>Display</td>
<td class="precio">1300</td>
</tr>
<tr>
<td>Keyboard</td>
<td class="precio">300</td>
</tr>
<tr>
<td><b>Total:</b></td>
<td class="total_prt"><b>$</b></td>
</tr>
</tbody>
</table>
<br>
<table class="table table-striped">
<thead>
<tr>
<th width="70%">Descripción</th>
<th width="20%">Precio</th>
</tr>
</thead>
<tbody>
<tr>
<td>HDD</td>
<td class="precio">400</td>
</tr>
<tr>
<td>System</td>
<td class="precio">425</td>
</tr>
<tr>
<td>Something</td>
<td class="precio">350</td>
</tr>
<tr>
<td><b>Total:</b></td>
<td class="total_prt"><b>$</b></td>
</tr>
</tbody>
</table>
ベストと簡単に。ありがとう...私は終わりにjsを入れた...私は以前考え出したと思うが、私は間違いをする... –