jquery - 为什么每次删除行时表中的数据都会计算两次
问题描述
简单的 pos 系统 我在一个基本的 pos 系统中工作,我确实想从具有的订单详细信息表中删除订单项目(“项目代码、描述、单价、数量、总计”)。问题是当我删除我的行时,总数从小计中减去两次并给出错误的计算。我不明白为什么它会这样工作。如果有人可以帮助解决这个问题,真的很感激。谢谢你。
这是我的代码..
html代码-
<div id="tblContainer" class="table-dark">
<table id="tblOrderDetails" class="table table-hover table-dark">
<thead>
<tr>
<th class="text-center">Item Code</th>
<th>Description</th>
<th>Unit Price</th>
<th class="text-center">Qty</th>
<th class="text-right">Total</th>
<th></th>
</tr>
</thead>
<tbody id="orderdetailsbody">
</tbody>
</table>
</div>
<div>
<span id="spnTotal">Total: <label id="lblTotal">0.0</label></span>
<button id="btnPlaceOrder" class="btn btn-primary"> <i class="fas fa-cart-arrow-down"></i>
Place Order</button>
</div>
$("#tblOrderDetails tr td:last-child div").click(function(){
var deleteQty = parseInt($(this).parent().parent().find("td:nth-child(4)").text());
var deleteItem = $(this).parent().parent().find("td:first-child").text();
for(i=0; i<ITEMS.length;i++){
if(deleteItem == ITEMS[i].code){
ITEMS[i].qtyOnHand += deleteQty;
}
}
var newTotal = 0;
var subTotal = parseFloat($("#lblTotal").text());
var rowTotal = parseFloat($(this).parent().parent().find("td:nth-child(5)").text());
newTotal = subTotal - rowTotal;
$("#lblTotal").text(newTotal);
$(this).parent().parent().fadeOut(500);
var row = $(this).parent().parent();
setTimeout(function(){
row.remove();
},600);
});
解决方案
推荐阅读
- javascript - 如何避免在 axios 中发送多个重复的 AJAX 请求
- c# - 在 Virtual Box 中还原虚拟机快照时出错
- javascript - React 展示/容器组件分离
- java - login.microsoftonline.com:名称或服务未知
- javascript - 使用 JavaScript 让 POST API 与 ajax 一起工作
- uuid - uuidv1() 的生成方式是否不同?
- winapi - 使用 Python3 在 Windows 上共享目录
- jquery - 制作(动态生成)Textarea 属性 Autofocus & 必需
- fiware-orion - HTTPS 通知未到达 cygnus
- java - 如何为 pdf 文件创建功能编写 JUnit 测试用例