我有这个功能:
$("#inc<?php echo"$key"; ?>").click(function(){
prod_id = "<?php echo"$key"; ?>";
$.ajax({
type: "POST",
url: "updateproduct2cart.php",
data: "itemid="+prod_id+"&act=update&qty=up"
});
var currentValue = $("#inc<?php echo"$key"; ?>").closest('#SCprodsB').next('#SCprodsF').find('#totalCommande').html();
currentValue = parseFloat(currentValue);
$(":text[name='qty<?php echo"$key"; ?>']").val(Number($(":text[name='qty<?php echo"$key"; ?>']").val()) + 1);
var totalItems = parseFloat($("#qty<?php echo"$key"; ?>").val());
var priceItem = parseFloat(<?php echo"$priceProduct"; ?>).toFixed(2);
var totalValueUp = parseFloat(priceItem * totalItems).toFixed(2);
$("#subtotal<?php echo"$key"; ?>").html("€ "+ totalValueUp);
/* PART BELOW IS NOT WORKING PROPERLY*/
var numItems = parseFloat($(":text[name='qty<?php echo"$key"; ?>']").val());
var totalPriceItems = parseFloat(priceItem * numItems).toFixed(2);
var newValue = parseFloat(currentValue + totalPriceItems).toFixed(2);
$("#inc<?php echo"$key"; ?>").closest('#SCprodsB').next('#SCprodsF').find('#totalCommande').html(newValue);
});
这是 HTML 部分:
<table id="SCproduits" summary="commande">
<caption></caption>
<thead>
<tr>
<th scope="col">--</th>
<th scope="col">--</th>
<th scope="col">--</th>
<th scope="col">--</th>
<th scope="col">--</th>
<th scope="col">--</th>
<th scope="col">--</th>
<th scope="col">--</th>
</tr>
</thead>
<tbody id="SCprodsB">
<tr id="prodItemi3" name="prodItemi3">
<tr id="prodItemi4" name="prodItemi4">
<th id="prodItemi4" scope="row">xxxxxxxxx</th>
<td>xxx</td>
<td>
<td>
<button id="deci4" class="SCbutton">-</button>
<input id="qtyi4" class="SCinput3" type="text" size="2" value="1"
name="qtyi4">
<button id="inci4" class="SCbutton">+</button>
</td>
<td>
<td>
<td>
<td>
</tr>
</tbody>
<tfoot id="SCprodsF">
<tr>
<th scope="row"></th>
<td colspan="7">€ <span id="totalCommande">xxx</span>
</td>
</tr>
</tfoot>
</table>
使用 (inci4 按钮) 时,我无法使用正确的总值更新 (span id="totalCommande")。任何的想法 ?我走错路了吗?谢谢