<div class="cart_content" th:each="oIdList:${orderIdList}">
<table>
<tr class="table_head">
<th>订单号</th>
<th colspan="3">商品</th>
<th>商品金额</th>
<th>商品数量</th>
<th>总金额</th>
</tr>
<tr><td rowspan="0"><span th:text="${oIdList}"></span></td></tr>
<tr class="table_content" th:each="o:${orderList}" th:if="${oIdList}==${o.id}" >
<td class="show_img">
<img th:src="${o.image}" th:value="${o.sid}"
th:title="${o.name}"/>
</td>
<td class="title" colspan="2"><span th:text="${o.name}">商品名字</span></td>
<td class="cost">¥<span th:text="${o.price}">20.00</span>元</td>
<td class="count"><span class="minus">-</span><span class="number" th:text="${o.quantity}">2</span><span class="add">+</span>
</td>
<td class="per_sum">¥<span th:with="sum=${o.price}*${o.quantity}" th:text="${sum}">40.00</span>元</td>
</tr>
<tr class="table_content_del_img">
<td class="delete_img" rowspan="0"><img th:src="@{img/delete_icon.jpg}" th:value="${oIdList}" class="deleteShopCar"/>删除订单</td>
</tr>
<tr class="end_pay">
<!-- <td class="is_all"><input id="all" type="checkbox" checked="checked"/>全选</td>-->
<!-- <td class="space" colspan="3"></td>-->
<td colspan="4" class="all_sum">总价:¥<span>500.00</span>元</td>
<td colspan="1" class="pay_button_div">
<button class="pay_button">结算</button>
</td>
</tr>
</table>
</div>
<script>
function calSum() {
var sum = 0;
$('.cart_content').each(function(){
// console.log($(this));
let arr_tr = $(this).find(".per_sum").children("span");
let sum=0;
$.each(arr_tr,function (index,domEle) {
console.log("index: domEle:",index,domEle.innerText);
sum+=parseFloat(domEle.innerText);
})
sum = returnFloat(sum); //保留两位小数
console.log("sum:",sum);
// //给赋值
$(this).find('.end_pay').children(".all_sum").children("span").text(sum);
})
</script>
$('.cart_content').each(function(){} 遍历class名为.cart_content的div块。
$.each(arr_tr,function (index,domEle) {} 遍历jq集合对象,注意domEle
是js对象,而不是jq。