亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在結帳總額的末尾添加零?

如何在結帳總額的末尾添加零?

慕尼黑5688855 2023-09-18 15:19:37
我想在結帳總金額上有一個零,因為在末端以零結尾的產品上,總金額顯示為這樣 £1.5那么,如何更改它以像這樣顯示1.50英鎊而不會弄亂其他產品呢?任何代碼片段都將不勝感激。<!DOCTYPE html><html><head>   </head><body><header class="main-header">    <nav class="main-nav nav">    </nav></header>    <div class="shop-items">        <div class="shop-item">            <span class="shop-item-title">Album 0</span>&nbsp;            <div class="shop-item-details"><span class="shop-item-price">£12.50</span>            <button class="btn btn-primary shop-item-button" type="button">ADD TO BASKET</button>        </div>  <div class="shop-item">        <span class="shop-item-title">Album 2</span>&nbsp;        <div class="shop-item-details">            <span class="shop-item-price">£14.50</span>                       <button class="btn btn-primary shop-item-button" type="button">ADD TO BASKET</button>        </div>        <div class="shop-item">        <span class="shop-item-title">Album 4</span>&nbsp;        <div class="shop-item-details"><span class="shop-item-price">£19.50</span>        <button class="btn btn-primary shop-item-button" type="button">ADD TO BASKET</button>    </div>        </div></section>    <div class="shop-items">        <div class="shop-item">            <span class="shop-item-title">Album 6</span>&nbsp;            <div class="shop-item-details"><span class="shop-item-price">£19.50</span>            <button class="btn btn-primary shop-item-button" type="button">ADD TO BASKET</button>        </div>     <div class="shop-items">        <div class="shop-item">            <span class="shop-item-title">Album 8</span>&nbsp;            <div class="shop-item-details"><span class="shop-item-price">£19.50</span>            <button class="btn btn-primary shop-item-button" type="button">ADD TO BASKET</button>        </div>   
查看完整描述

1 回答

?
慕森卡

TA貢獻1806條經驗 獲得超8個贊

在代碼末尾,將此代碼編輯為totaltotal.toFixed(2)


編輯:


在代碼的最后一行


function updateCartTotal() {

var cartItemContainer = document.getElementsByClassName('cart-items')[0]

var cartRows = cartItemContainer.getElementsByClassName('cart-row')

var total = 0

for (var i = 0; i < cartRows.length; i++) {

    var cartRow = cartRows[i]

    var priceElement = cartRow.getElementsByClassName('cart-price')[0]

    var quantityElement = cartRow.getElementsByClassName('cart-quantity-input')[0]

    var price = parseFloat(priceElement.innerText.replace('£', ''))

    var quantity = quantityElement.value

    total = total + (price * quantity)

}

total = Math.round(total * 100) / 100

document.getElementsByClassName('cart-total-price')[0].innerText = '£' + total.toFixed(2)

}


查看完整回答
反對 回復 2023-09-18
  • 1 回答
  • 0 關注
  • 110 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號