這個想法是能夠洗掉表格行的最后一列,包含標題 Sel。和復選框。該函式洗掉所有內容,包括表格頁腳行的單元格,這是總計所在的位置,然后該值將丟失。
該函式在用戶單擊 print 并使用時運行window.print(),但表格在視覺上錯過了總數。
const allRows = document.getElementById("dtable").rows;
for (let i = allRows.length - 1; i > 0; i--) {
allRows[i].deleteCell(-1);
}
<html>
<head>
<base target="_top">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM B07jRM" crossorigin="anonymous">
</script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js" integrity="sha384-xrRywqdh3PHs8keKZN 8zzc5TX0GRTLCcmivcbNJWm2rs5C8PRhcEn3czEjhAO9o" crossorigin="anonymous">
</script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" integrity="sha512-9usAa10IRO0HhonpyAIVpjrylPvoDwiPUiKdWk5t3PyolY1cOd4DSE0Ga ri4AuTroPR5aQvXU9xC6qOPnzFeg==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.4/jspdf.debug.js"></script>
</head>
<table class="table table-hover table-vcenter" id="dtable">
<thead>
<tr>
<th style="width:5%">Yards</th>
<th style="width:8%">Total FOB</th>
<th style="width:4%">Sel.</th>
</tr>
</thead>
<tbody id="tableRows">
<tr>
<td><input type="number" min="0" class="qty" name="numberInputs" value="" onchange="add_to_total(this); deposit(term())"></td>
<td class="total_price"><strong>$0.00</strong></td>
<td><input type="checkbox"></td>
</tr>
<tr>
<td><input type="number" min="0" class="qty" name="numberInputs" value="" onchange="add_to_total(this); deposit(term())"></td>
<td class="total_price"><strong>$0.00</strong></td>
<td><input type="checkbox"></td>
</tr>
</tbody>
<tfoot>
<tr>
<td id="totalTitle" colspan="2" align="right"><strong>Total:</strong></td>
<td id="totalValue" class="total">$0.00</td>
</tr>
<tr>
<td id="termsRow" colspan="1" align="right"><strong>Deposit(%):</strong></td>
<td><input type="number" id="term" min="0" class="terms" name="numberInputs" value="" onchange="deposit(this)"></td>
<td id="termsTotal" class="total_terms"><strong></strong></td>
</tr>
</tfoot>
</table>
</html>
感謝你的幫助
uj5u.com熱心網友回復:
從最后一行開始,而不是從最后一行開始:
for (let i = allRows.length - 3; i > 0; i--) { // 3, not 1!
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/507577.html
標籤:javascript
上一篇:使用正則運算式捕獲文本
下一篇:正則運算式捕獲組
