我有点新的JS/jQuery和这个网站是shopify所以我不能做太多的功能,所以试图解决与JS,但我需要抓住价值,剥离货币,然后将它们添加在一起,并重新显示,但这是尽可能得到,但没有工作...
任何想法?
setTimeout(function() {
var a = $(".cart-total span").html().replaceText(/$|£/gi, "");
var b = $("#estimated-shipping em").html().replaceText(/$|£/gi, "");
var total = a + b;
$('.cart-finalTotal span').html("£" + total);
console.log(total);
}, 1000);
<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">£249.00</span>
</p>
<p class="cart-vat">VAT 20% (included)<span class="money">£49.80</span>
</p>
<p class="cart-delivery">Delivery<span class="money" id="estimated-shipping">+ <em>$9.00</em></span>
</p>
<p class="cart-finalTotal">Total<span class="money">£249.00</span>
</p>
<div class="cart-checkout">
<button class="button button-primary button-add-to-cart button-pay-now" type="submit" name="checkout"><span class="icom-lock"></span>Pay Now</button>
<br>
<br>
<div class="additional-checkout-buttons">
<p>Or checkout with</p>
<img id="applePayButton" style="display: none" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" onload="typeof createApplyPayButton === 'function' ? createApplyPayButton(this) : window.addEventListener('applePayReady', (function(){createApplyPayButton(this)}).bind(this))">
<input type="image" name="goto_pp" value="paypal_express" src="https://www.paypalobjects.com/en_US/i/btn/btn_xpressCheckout.gif">
</div>
</div>
</div>
请注明“不工作” ...... – Connum
我觉得你的正则表达式是错误的。 $符号表示字符串结尾。你应该使用\ – CyberAleks
来避免它\ \在$之前添加\但在控制台中我看到:$(...)。html(...)。replaceText不是函数 – James