Помогите найти общую сумму корзины при нажате плюс минус
это корзина
<main> <table class="shopping_list"> <tr> <th>Image</th> <th>Name</th> <th>Price</th> <th>Quantity</th> <th>Total</th> <th>Action</th> </tr> <?php $total = 0; include "basket/connect.php"; $sql = "SELECT * FROM `basket` "; $result = mysqli_query($con, $sql); if (mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_assoc($result)){ ?> <tr> <td><img src=img/<?php echo $row['image_url'];?>> </td> <td><?php echo $row['name'];?> </td> <td>$ <?php echo $row["price"];?></td> <td> <button class="minus" type="button" style="width:17%;"> <i class="fa fa-minus"></i></button> <input class="quantity" type="text" value='<?php echo $row["quantity"]; ?>' style="width:17%;"/> <button class="plus" type="button" style="width:17%;"><i class="fa fa-plus"></i></button> </td> <td><span class="count_price" data-price="<?php echo $row["price"]; ?>">$ <?php echo $row["price"]; ?> </span></td> <td> <form method="POST" action='basket/delete.php ?id=<?php echo $row["id"] ?> '> <input type="submit" name="delete" value="Remove"> </form></td> <?php $total = $total + $row["price"]; ?> </tr> <?php } } ?> <tr> <td colspan="4" align="right">Total</td> <td> $ <?php echo number_format($total,2); ?></td> <td></td> </tr> </table> |
Вот так выглядит моя Jquery
jquery
$(document).ready(function() { function change($tr, val) { var $input = $tr.find('.quantity'); var count = parseInt($input.val()) + val; count = count < 1 ? 1 : count; $input.val(count); var $price = $tr.find('.count_price'); $price.text(count * $price.data('price')); } $('.minus').click(function() { change($(this).closest('tr'), -1); }); $('.plus').click(function() { change($(this).closest('tr'), 1); }); $('.quantity').on("input", function() { var $price = $(this).closest('tr').find('.count_price'); $price.text(this.value * $price.data('price')); }); }); как взять количество и получить окончательную сумму |
Asta,
если бы ваш макет выглядел примерно так , а не вот это всё. |
Часовой пояс GMT +3, время: 23:39. |