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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>...</title>
<style>
td, th {min-width:80px;border:inset 2px silver;;text-align:center}
</style>
</head>
<body>
<div id="c"></div>
<script>
window.addEventListener("load",()=>{
function eleve (nom, prénom, age, note1, note2, note3, note4){
this.nom = nom;
this.prenon = prénom;
this.age = age;
this.notes = [note1, note2, note3, note4]
}
const unTableauEtudiant = [
new eleve('a', 'aa', 18, 12, 13, 10, 15),
new eleve('b', 'bb', 19, 14, 12, 14, 12),
new eleve('c', 'cc', 17, 13, 19, 10, 8),
new eleve('d', 'dd', 20, 15, 10, 15, 9),
new eleve('e', 'ee', 21, 16, 13, 18, 10),
];
const t=document.createElement("table");
const tb=document.createElement("tbody");
const thead=document.createElement("thead");
thead.style.background="grey";
t.appendChild(thead);
t.appendChild(tb)
document.getElementById("c").appendChild(t);
unTableauEtudiant.forEach((v,i)=>{
let tr=document.createElement("tr");
if(i%2==1){
tr.style.background="orange"
}
if(i==0){
for(prop in v){
let th=document.createElement("th");
thead.appendChild(tr);
tr.appendChild(th);
th.textContent=prop;
}
}
else{
for(prop in v){
let td=document.createElement("td");
tb.appendChild(tr)
tr.appendChild(td);
td.textContent=v[prop];
}
}
})
</script>
</body>
</html> |
Partager