我有一个独特的商业模式,我们的价格每增加3项意味着
购物车中的1-3个项目=X成本
4-6件=2倍成本
7-9件=3倍成本
如果一个人的购物车里有1到2件商品,我想让他们知道,他们仍然可以将3件商品的差额加到购物车上,并支付相同的价格(用他们的钱获得最大的回报)。如果不等于0,如何检查购物车中的商品总数量,然后根据商数显示msg?
如果您需要更多信息,我很乐意提供尽可能多的信息。
谢谢!
发布于 2015-11-12 07:18:13
在页面加载或项目选择时附加一个函数,这就是你提到的。我可能把这件事搞得太复杂了,但还是尽量保持简单。使用现有的“add item”和onload函数:
var quantity = 0;
$(document).load(init());
function init()
{
quantity % 3 > 0 ? $('#quant').show() : $('#quant').hide();
$('#num').html(3 - (quantity % 3));
}
function addOne() // your buy function
{
quantity++;
init();
$('#total').html(quantity);
}div#quant
{
width: 100%;
text-align: right;
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="quant">Buy
<span id="num"></span>
more for free!
</div>
<br>
<button onclick="addOne()">Buy Item</button>
<h3>Total: <span id="total"></span></h3>
https://stackoverflow.com/questions/33661381
复制相似问题