I have got a table with redundant data in cells. [Left table]
I need to join them into one cell. [Right table]
Structure of table:
<table>
<tr>
<td class="bold">Value1:</td>
<td class="green">A</td>
<td class="green">A</td>
<td class="green">A</td>
<td> </td>
<td> </td>
<td> </td>
<td class="green">B</td>
<td class="green">B</td>
</tr>
<tr>
<td class="bold">Value2:</td>
<td> </td>
<td> </td>
<td class="green">C</td>
<td class="green">C</td>
<td> </td>
<td> </td>
<td class="green">D</td>
<td> </td>
</tr>
</table>
I am able to hide redundant cell, but I need to set colspan somehow.
$(document).ready(function () {
var all = $('.green');
var seen = {};
all.each(function () {
var txt = $(this).text();
if (seen[txt]) {
$(this).hide();
}
else {
seen[txt] = true;
}
});
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…