我有一个表格,其中有一行文本框作为输入,用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