我想将来进行A / B测试。为此,我在Magento稍微更换了一下购物车。我的代码是:
<ol id="cart-sidebar" class="mini-products-list clearer">
<li class="item">
<div class="product-details">
<p class="product-name">Product #1</p>
<strong>6</strong><br/>
<span class="price">9,14 €</span>
</div>
</li>
<li class="item">
<div class="product-details">
<p class="product-name">Product #2</p>
<strong>3</strong><br/>
<span class="price">7,36 €</span>
</div>
</li>
<li class="item">
<div class="product-details">
<p class="product-name">Product #3</p>
<strong>3</strong><br/>
<span class="price">7,36 €</span>
</div>
</li>
</ol>
在每个&#34;项目&#34;我想将<strong>
标记中的值与价格相乘,因为它只是一个数量。然后我想用<span class="price">
替换产品的实际成本。
将它乘以的方法可能是
var one = parseInt($(".itemOne").text(), 10);
var two = parseInt($(".itemTwo").text(), 10);
$(".total").text(one * two);
但我不知道如何替换价值以及如何摆脱
和€。也许你们有个主意?!
答案 0 :(得分:2)
您可以使用解决方案
$('li').each(function() {
var cost = (parseFloat($(this).find('span.price').text().replace(',','.')) * parseInt($(this).find('strong').text())).toFixed(2);
$(this).find('span.price').text(cost + ' €');
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ol id="cart-sidebar" class="mini-products-list clearer">
<li class="item">
<div class="product-details">
<p class="product-name">Product #1</p>
<strong>6</strong><br/>
<span class="price">9,14 €</span>
</div>
</li>
<li class="item">
<div class="product-details">
<p class="product-name">Product #2</p>
<strong>3</strong><br/>
<span class="price">7,36 €</span>
</div>
</li>
<li class="item">
<div class="product-details">
<p class="product-name">Product #3</p>
<strong>3</strong><br/>
<span class="price">7,36 €</span>
</div>
</li>
</ol>
&#13;
希望这会对你有所帮助。