我想要的是每一行都应该有它的总和(row1=price x 数量),因为数量变化总和应该自动变化(total=row1 + row2 +row3)所以所有行的总数。因为它只是能够通过第一行实现这一目标。在这里测试我的代码 https://malawiclinic.000webhostapp.com/
<form class="form-inline">
<?php
$sqlm="SELECT * FROM tbl_wishlist ORDER BY id DESC ";
$resultmn=mysqli_query($db,$sqlm);
$fcount=mysqli_num_rows($resultmn);
if ($fcount>0) {
$countprice=0;
while($found = mysqli_fetch_array($resultmn)) {
$product = $found['product'];
$qty = $found['Quantity'];
$price = $found['price'];
echo "
<div class='form-group'>
<label for='exampleInputName2'>$product</label>
<input type='text' class='form-control' id='price'
value='$price'>
</div>
<div class='form-group'>
<input type='number' class='input-text form-control'
id='quantity' value='$qty'>
</div>
<label for='exampleInputName2'>$
<span id='result'></span>
</label>";
}
} ?>
</form>
<script type="text/javascript">
$(document).ready(function(){
$(document).on("input",".input-text", function(){
var x = document.getElementById("quantity").value;
var x1 = document.getElementById("price").value;
var total = x1 * x;
var totals = total.toLocaleString(undefined,
{maximumFractionDigits:2});
$("#result").html(totals);
$("#totals").html(totals);
});
});
</script>
MYYA
相关分类