请问确认订单页面小计数量怎么获取?
如图,我想获取单个模块里面的小计前面共几件,我的写法只有第一块是正确的,第二块的小计会连第一块的一起加上去,这样不对,我要怎样让每一块小计都单独显示。
<div class="weui-tab"><div class="weui-tab__panel">
<div class="qddls-main qddls-ordermain">
<div class="qddls-cards">
<div class="qddls-carname">
<a href="https://segmentfault.com/q/1010000023453968/javascript:;" class="check-label check-local-part">
<b class="check-name"><img src="https://segmentfault.com/q/1010000023453968/images/qddls-katong.png" alt="" /><i>店铺名</i></b>
</a>
</div>
<div class="qddls-carorder">
<div class="qddls-ordertop">
<span class="qddls-orderimg"><img src="https://segmentfault.com/q/1010000023453968/images/img1.jpg" alt="" /></span>
<div class="qddls-caright">
<span class="order-cartitle"><em>这个是产品标题</em><i>¥<b>198</b>.00</i></span>
<span class="order-carnum"><em>NB 2包装</em><i>x1</i></span>
</div>
</div>
<div class="qddls-orderbottom">
<div
class="weui-cell weui-cell_active weui-cell_access weui-cell_select weui-cell_select-after">
<div class="weui-cell__hd"><label class="weui-label">配送方式</label></div>
<div class="weui-cell__bd showPicker">普通配送 快递免邮</div>
</div>
<div class="weui-cell weui-cell_active">
<div class="weui-cell__hd"><label class="weui-label">订单备注</label></div>
<div class="weui-cell__bd">
<input class="weui-input" placeholder="订单备注">
</div>
</div>
<span class="pay_xiaoji"><em>共1件</em> 小计:<b>¥</b><i>98</i><b>.00</b></span>
</div>
</div>
</div>
<div class="qddls-cards">
<div class="qddls-carname">
<a href="https://segmentfault.com/q/1010000023453968/javascript:;" class="check-label check-local-part">
<b class="check-name"><img src="https://segmentfault.com/q/1010000023453968/images/qddls-katong.png" alt="" /><i>店铺名</i></b>
</a>
</div>
<div class="qddls-carorder">
<div class="qddls-ordertop">
<span class="qddls-orderimg"><img src="https://segmentfault.com/q/1010000023453968/images/img2.jpg" alt="" /></span>
<div class="qddls-caright">
<span class="order-cartitle"><em>这个是产品标题</em><i>¥<b>198</b>.00</i></span>
<span class="order-carnum"><em>NB 2包装</em><i>x3</i></span>
</div>
</div>
<div class="qddls-orderbottom">
<div
class="weui-cell weui-cell_active weui-cell_access weui-cell_select weui-cell_select-after">
<div class="weui-cell__hd"><label class="weui-label">配送方式</label></div>
<div class="weui-cell__bd showPicker">普通配送 快递免邮</div>
</div>
<div class="weui-cell weui-cell_active">
<div class="weui-cell__hd"><label class="weui-label">订单备注</label></div>
<div class="weui-cell__bd">
<input class="weui-input" placeholder="订单备注">
</div>
</div>
<span class="pay_xiaoji"><em>共1件</em> 小计:<b>¥</b><i>98</i><b>.00</b></span>
</div>
</div>
</div>
</div>
</div>
<div class="weui-tabbar payment-tabbar">
<div class="qddls-allbtn">
<div class="cart-foot-right">
<span class="cartright_span">共1件,</span>
<em class="total-bill">合计:<span class="bill-price">¥<i
class="all-price">487</i>.55</span></em>
<a href="https://segmentfault.com/q/1010000023453968/javascript:;" class="order-btn ban-order" id="showIOSDialog1">提交订单</a>
</div>
</div>
</div>
</div>
// 获取总额var allNum = 0;
var numDan = 0;
$(".qddls-ordertop").each(function(){
var jiage=parseInt($(this).find(".order-cartitle b").text()); //获取全部单价
var num=parseInt($(this).find(".order-carnum i").text().match(/\d+/)); //获取全部订单数量
numDan+=num;
$(this).siblings(".qddls-orderbottom").find(".pay_xiaoji em").text("共"+ numDan +"件");
var numJisuan=jiage*num;
allNum += numJisuan;
$(".all-price").text(allNum.toFixed(2)); //合计
});
回答
我们先来分析一下DOM
.qddls-main
是全量商品.qddls-cards
是店铺商品,你希望这个小计是店铺的.qddls-carorder
是店铺商品详情.order-carnum
当前商品数量
.pay_xiaoji
是当前商铺的小计
·cartright_span
是总计
那么问题已经很简单了,$('.qddls-cards')
遍历,找到下面的 $('.order-carnum')
计算后给 $('.pay_xiaoji')
以上是 请问确认订单页面小计数量怎么获取? 的全部内容, 来源链接: utcz.com/a/36662.html