一个店铺有多个商品,请问怎么计算选中的商品的总价
- 发布:2018-05-19 09:22
- 更新:2018-05-21 10:57
- 阅读:2292
新生 - 慢慢进步的菜鸟
$(function() {
//加的效果
$("#reservationtable").on("click",".add",function() {
$(this).prevAll().css("display", "inline-block");
var n = $(this).prev().text();
var num = parseInt(n) + 1;
// console.log(num);
if(num == 0) {
return;
}
$(this).prev().text(num);
var danjia = $(this).next().text(); //获取单价
var a = $("#totalpriceshow").html(); //获取当前所选总价
$("#totalpriceshow").html((a 1 + danjia 1).toFixed(2)); //计算当前所选总价
var nm = $("#totalcountshow").html(); //获取数量
$("#totalcountshow").html(nm * 1 + 1);
jss(); //<span style='font-family: Arial, Helvetica, sans-serif;'></span> 改变按钮样式
});
//减的效果
$("#reservationtable").on("click",".minus",function() {
var n = $(this).next().text();
var num = parseInt(n) - 1;
// console.log(num);
$(this).next().text(num); //减1
var danjia = $(this).nextAll(".price").text(); //获取单价
var a = $("#totalpriceshow").html(); //获取当前所选总价
$("#totalpriceshow").html((a * 1 - danjia * 1).toFixed(2)); //计算当前所选总价
var nm = $("#totalcountshow").html(); //获取数量
$("#totalcountshow").html(nm * 1 - 1);
//如果数量小于或等于0则隐藏减号和数量
if(num <= 0) {
$(this).next().css("display", "none");
$(this).css("display", "none");
jss(); //改变按钮样式
return
}
});
function jss() {
var m = $("#totalcountshow").html();
if(m > 0) {
$(".right").find("a").removeClass("disable");
} else {
$(".right").find("a").addClass("disable");
}
};
HTML:
<div class="main mui-content" style="margin-top: 64px;">
<div class="con">
<div class="right-con con-active">
<ul class="mui-table-view mui-grid-view mui-grid-9" style="margin-bottom: 46px;" id="reservationtable">
<li class="mui-col-sm-3 mui-col-xs-4 mui-table-view-cell ">
<div class="menu-img" align="center"><img src="../../../images/zjm.jpg" width="55" height="55" /></div>
<div class="menu-txt" align="center">
<h4>炸酱面</h4>
<p class="list2">
<b>¥15(份)</b>
<div class="btn">
<button class="minus">
<strong></strong>
</button>
<i>0</i>
<button class="add">
<strong></strong>
</button>
<i class="price">15</i>
</div>
</p>
</div>
</li>
<div class="footer">
<div class="left">已选:
<span id="cartN">
<span id="totalcountshow">0</span>份 总计:¥<span id="totalpriceshow">0</span></span>元
</div>
<div class="right">
<a id="btnselect" class="xhlbtn disable" href="javascript:void(0)">去结算</a>
</div>
</div>
</ul>
</div>
</div>