你试试看
![[吐舌]](/static/emoticons/u5410u820c.png)
学号:<input class="student" type="text" oninput="oStudent.sid=this.value" value="" /><br />
姓名:<input class="student" type="text" oninput="oStudent.name=this.value" value="" /><br />
年龄:<input class="student" type="text" oninput="oStudent.age=this.value" value="" /><br />
<input type="button" onclick="fnStudent(document.getElementById('demo'))" value="输出" />
<p id="demo"></p>
<p id="stu-data"></p>
<script>
// 2
let oStudent = {};
const fnStudent = o => {
if (!([...document.querySelectorAll('.student')].every(e => e.value && e.value.trim()))) return (o.innerHTML = '', alert('其中有空白!!!'));
o.innerHTML = Object.values(oStudent).join('<br />');
};
// 3
class ClStudent {
constructor(sid, name, _class,
chinese, mathematics, totalScore) {
this.sid = sid;
this.name = name;
this._class = _class;
this.chinese = chinese;
this.mathematics = mathematics;
this.totalScore = totalScore;
}
}
let aStuData = [new ClStudent(10, '小明', '一年一斑', 60, 50, 110), new ClStudent(20, '小芳', '二年二班', 70, 60, 130), new ClStudent(30, '张三', '三年三班', 50, 50, 100), new ClStudent(40, '李四', '一年四班', 70, 70, 140), new ClStudent(50, '王五', '二年一班', 20, 90, 110)],
oIdStu = document.getElementById('stu-data');
oIdStu.innerHTML = aStuData.map(c => `学号: ${c.sid}, 姓名: ${c.name}, 班级: ${c._class}, 语文: ${c.chinese}, 数学: ${c.mathematics}, 总分: ${c.totalScore}`).join('<br />') + `<br />
语文平均分: ${aStuData.reduce((p, n) => p + n.chinese, 0) / aStuData.length}<br />
数学平均分: ${aStuData.reduce((p, n) => p + n.mathematics, 0) / aStuData.length}`;
</script>