我有一個表格,其中有一行文本框作爲輸入,用css .hours保存數字/小時。我正在嘗試to get the table to update totals
刪除行時checkbox is checked
/clicked。複選框JavaScript不會更新值
如何更新最後一行中的總數& col?當刪除行複選框被選中。
2個步驟:我將被刪除行中的值清零,然後想要更新新的總計。
// Call this function, When CheckBox with css .deleteRowis clicked
$('#Maintable').on('click', '.deleteRow', function()
{
if ($(this).is(":checked")) {
var row = $(this).closest('tr').css({ 'color': 'red' });
var hours = row.find('.hours');
$.each(hours, function (index, item) {
if ($(this).val()) { // if there is a value
$(this).val('0');
// Total the rows does not work??
HoursChangedFunction($(this));
}
});
} // :checked ends
// when the row is deleted from the checkbox, find it and call this function
// 1) First make all .hours 0, 2) and then redo the totals
var HoursChangedFunction = function() {
var columnIndex = $(this).closest('td').index();
var row = $(this).closest('tr');
var hours = row.find('.hours');
var rowTotal = 0;
$.each(hours, function (index, item) {
rowTotal += Number($(this).val());
});
row.children('td.rowtotal').text(rowTotal.toFixed(2));
var columnTotal = 0;
var grandTotal = 0;
var rows = $('#Maintable tr');
$.each(rows, function (index, item) {
columnTotal += Number($(this).children('td').eq(columnIndex).children('.hours').val());
grandTotal += Number($(this).children('.rowtotal').text());
});
footer.eq(columnIndex).text(columnTotal.toFixed(2));
total.text(grandTotal.toFixed(2));
};
頁腳和總沒有定義,是什麼頁腳? – Nicholas
@Nicholas footer是'totalals'爲'daily columns'的底行,我會在秒內加上 – transformer
@Nicholas它應該是'tfoot'這真的是桌腳 – transformer