标签:
需求:相同的产品名称,要合并单元格,并计算出相同产品总共消耗多少标煤。
function autoRowSpan(tb, row, col) { var lastValue = ""; var value = ""; var pos = 1; var tdSum = 0; var cellValue = 0; for (var i = row; i < tb.rows.length; i++) { value = tb.rows[i].cells[col].innerText; if (lastValue == value) {//判断产品名称是否相同 if (!isNaN(tb.rows[i].cells[4].innerText))//判断是否为数字类型 cellValue =cellValue+ parseFloat(tb.rows[i].cells[4].innerText); tb.rows[i].deleteCell(col); tb.rows[i - pos].cells[col].rowSpan = tb.rows[i - pos].cells[col].rowSpan + 1;//设置单元格rowSpan的值 var z = tb.rows(i).cells.length; tb.rows[i].deleteCell(z - 1); tb.rows[i - pos].cells[z].rowSpan = tb.rows[i - pos].cells[z].rowSpan + 1//合并标煤合计那一列的单元格 tb.rows[i - pos].cells[5].innerText = cellValue;//进行复制 pos++; } else {//产品名称不同的处理 lastValue = value; cellValue = parseFloat(tb.rows[i].cells[4].innerText); if (!isNaN(cellValue)) tb.rows[i].cells[5].innerText = cellValue; pos = 1; tdSum = 0; } } }
标签:
原文地址:http://www.cnblogs.com/kmonkeywyl/p/5452517.html