1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| <table border="1"> <thead>
<tr>
<th class="ta-amwm" colspan="4" id="Titre">Calcul</th>
</tr>
<tr>
<th class="ta-v25l" id="compteT">Compte</th>
<th class="ta-v25l" id="codeT">Code</th>
<th class="ta-v25l" id="calculT">Calcul</th>
<th class="ta-v25l">Résulat</th>
</tr>
</thead>
</table>
<script>
var tab = [
["A", "B", "C", "D"],
["A1", "C1"],
["A2", "B2", "C2", "D2"],
["A3", "C3"],
];
var nHTML = document.querySelector("table").innerHTML;
tab.forEach(function (arrItem, i) {
var td = "<tr>";
arrItem.forEach(function (item, i1) {
if (i % 2) {
// Si la ligne 2 ou 4
td += "<td colspan='3'>" + item + "</td>"; // créer une cellule de 3 cases
td += "<td>" + item + "</td>"; // crééer une deuxieme cellule
return; // passer à la ligne suivante
}
td += "<td>" + item + "</td>";
});
nHTML += td + "</tr>";
});
document.querySelector("table").innerHTML = nHTML;
</script> |
Partager