[英]Jquery/Javascript | HTML Table Sum Total Records of sibling TD in last TD
我正在嘗試基於該行中同級的總和來更新最后一個。
單擊時,表TD的類為contenteditable = "TRUE"
。
所以我正在嘗試當有人嘗試更新該td列上的數字時,它也應該更新該行中的最后一個。
這是我現在擺在桌子上的小提琴。
您可以計算出已編輯TD的模糊度
$('tr.tableRow td.inner').on('blur',function(e){
var sumTD = $(this).parent().find("td:last");
sumTD.text(parseInt(sumTD.text())+ parseInt($(this).text()));
});
檢查你的js小提琴鏈接
$('tr.tableRow td.inner').on('click',function(e){
e.preventDefault();
e.stopImmediatePropagation();
$(this).attr('contentEditable','true');
$(this).addClass('inputCopyCat');
$(this).focus();
});
$('tr.tableRow td.inner').focusout(function(e){
$('td.inputCopyCat').removeAttr('contentEditable');
$('td.inputCopyCat').removeClass('inputCopyCat');
var currentTableRow = $(this).parent();
var currentTabelRowSum = 0;
currentTableRow.find('td.inner:not(:last)').each(function() {
var userInput = parseInt(this.innerText);
if(!isNaN(userInput)) {
currentTabelRowSum += parseInt(this.innerText);
}
});
currentTableRow.find('td.inner:last').text(currentTabelRowSum);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.