Чтобы решить проблему, в которой субтотальный не отображается правильно в резюме тележки внизу, мы должны убедиться, что JavaScript правильно обновляет значение для элемента .sub_total в резюме тележки, как и для таблицы. подтотальный. Не отображать подножку, как выполнить эту проблему, я - новый PHP Devloper < /p>
Cart Summary
.fixed-bottom-clr1 {
background-color: #f8f9fa;
}
.badgescntr {
position: absolute;
left: 33%;
}
.medium {
font-size: 1.2rem;
}
Price List
Product Name
Price
Quantity
Total
Product 1
50
50
Product 2
30
30
Subtotal:
80
2 items .
80.00
|
2
View Cart
// Function to update the total when quantity changes
document.querySelectorAll('.product-quantity').forEach(input => {
input.addEventListener('input', updateCart);
});
function updateCart() {
let totalItems = 0;
let subTotal = 0;
// Loop through all product rows and calculate the total and subtotal
document.querySelectorAll('.product-quantity').forEach(input => {
const quantity = parseInt(input.value) || 0;
const price = parseFloat(input.getAttribute('data-price')) || 0;
const productTotal = quantity * price;
// Update the individual product total
input.closest('tr').querySelector('.product-total').textContent = productTotal.toFixed(2);
// Update subtotal and total items
subTotal += productTotal;
totalItems += quantity;
});
// Update subtotal in both table and cart summary
document.querySelector('.sub_total').textContent = subTotal.toFixed(2);
document.querySelector('.total_products_count').textContent = totalItems;
}
// Initial call to update the cart
updateCart();
Подробнее здесь: https://stackoverflow.com/questions/793 ... t-not-show