任何想法爲什麼我試圖一起計算的總數是1.00?jQuery計算兩個值錯誤,不知道爲什麼
$(document).ready(function() {
// Hide initial values that need updating
$("#estimated-shipping em, .cart-finalTotal span, .cart-vat span").hide();
// get current delivery rate
$("#get_rate").trigger('click');
// set a timeout and get total and shipping that was generated and add together for nnew total
setTimeout(function() {
// get cart sub-total
var a = $(".cart-total span").html().replace(/[$£]/gi, "");
var ib = $("#estimated-shipping em").html().replace(/[$£]/gi, "");
if (ib == "FREE") {
$("#estimated-shipping em").html("FREE");
var b = "0.00";
} else {
var b = parseFloat($("#estimated-shipping em").text().replace(/\$|£/gi, ""));
}
// add together sub-total and estimated shipping to new total
// update with new total with sub-total and added shipping
var total = parseFloat(a) + parseFloat(b);
total = parseFloat(Math.round(total * 100)/100).toFixed(2);
$('.cart-finalTotal span').text("£" + total);
// show new values
$("#estimated-shipping em, .cart-finalTotal span, .cart-vat span").show();
}, 2000);
$(".item-quantity input").on("change", function() {
document.location.href = location.href
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="cart-right">
<p class="cart-total">Sub-Total<span class="money">£1,245.00</span>
</p>
<p class="cart-vat">VAT 20% (included)<span class="money" style="display: block;">£249.00</span>
</p>
<p class="cart-delivery">Delivery (estimated)<span class="money" id="estimated-shipping">+ <em style="display: inline;">FREE</em></span>
</p>
<p class="cart-finalTotal">Total<span class="money" style="display: block;">£0.00</span>
</p>
</div>
要添加0和1? –
我是?我做了一個控制檯登錄和得到1,245.00和0.00作爲免費送貨 – James
當我測試代碼,它似乎確定,直到購物車總數超過1000,然後設置爲1? – James