var fail_cnt, pass_cnt = 0;
var arr_lec = [6, 8, 1.2, 7, 5];
var arr_lab = [6.4, 5, 0, 5, 6];
var sem_a = {lec: arr_lec, lab: arr_lab};
var table = document.querySelector("#table");
for (var i = 0; i < arr_lab.length; i++){
table.getElementsByTagName("td")[i,1].textContent = sem_a["lec"][i];
table.getElementsByTagName("td")[i,2].textContent = sem_a["lab"][i];
table.getElementsByTagName("td")[i,3].textContent = (sem_a["lec"][i] + sem_a["lab"][i])/2;
for (var j = 0; j < 4; j++){
if (table.getElementsByTagName("td")[i,3].textContent >= 5){
pass_cnt += 1;
table.getElementsByTagName("td")[i,j].style.background = "rgb(89, 196, 43)";
}
else{
fail_cnt += 1;
table.getElementsByTagName("td")[i,j].style.background = "rgb(255, 0, 0)";
}
table.getElementsByTagName("td").push(sem_a);
}
}
我想将sem_a的元素推到表对象中而不使用数组方法来执行此操作,因为它必须保留用于DOM操作的对象。