从字符串jquery中获取数值



我在span类中显示价格,我想添加所有的价格。要做到这一点,我必须删除货币(这是动态的)。

数据将是

<div class="js-price-cell">
<span class="js-price">$280.00</span>
</div>
<div class="js-price-cell">
<span class="js-price">$280.00</span>
</div>

I tried with

$form.find('.js-price-cell').each(function () {
let priceText= $(this).find('.js-price').text();
var itemTotal= parseFloat(priceText.replace(/[^0-9]/gi, ''));
totalAmt += itemTotal;
});

代替560.00。它给出了56000。似乎连.都被取代了。

您替换了priceText:所有非小数都被删除了。加上a。到正则表达式,它应该可以工作。

var itemTotal= parseFloat(priceText.replace(/[^0-9.]/gi, ''));