var form = document.getElementsByTagName('tbody')[0]; //form.children 获得表单的十五行 下标 1-15 var zongfen = 0;//分母和 var zongxuefen = 0; var product = 0;//分子和 var j = 0;
for (let i = 1; i < form.children.length; i++) { var credit = Number(form.children[i].children[9].innerText);//绩点 var score = Number(form.children[i].children[7].innerText);//成绩 var xuefen = Number(form.children[i].children[6].innerText)//学分 var kemu = form.children[i].children[4].innerText; if (form.children[i].children[5].innerText == '必修' && score >= 60) { j+=1; console.log(`${kemu} 学分:${xuefen} 成绩:${score} 绩点:${credit}`); zongfen+=credit*xuefen; zongxuefen+=xuefen; } } console.log('目前全部必修科目的平均加权绩点为'+(zongfen/zongxuefen).toFixed(2)) alert('目前全部必修科目的平均加权绩点为'+(zongfen/zongxuefen).toFixed(2)) zongfen = 0; zongxuefen = 0