有一个学员成绩json数组如下,要求以表格方式显示学员成绩表。 let scores = [ {"sid":1,"name":"岳不群","chinese":66,"maths":78}, {"sid":1,"name":"风清扬","chinese":86,"maths":65}, {"sid":1,"name":"东方不败","chinese":95,"maths":88}, {"sid":1,"name":"布袋和尚","chinese":36,"maths":69}, {"sid":1,
时间: 2023-06-28 18:06:46 浏览: 118
"name":"狄云","chinese":78,"maths":91} ];
可以使用HTML和JavaScript来实现成绩表格的显示,代码如下:
```html
<!DOCTYPE html>
<html>
<head>
<title>学员成绩表</title>
</head>
<body>
<table>
<tr>
<th>学号</th>
<th>姓名</th>
<th>语文成绩</th>
<th>数学成绩</th>
</tr>
<script>
let scores = [
{"sid":1,"name":"岳不群","chinese":66,"maths":78},
{"sid":2,"name":"风清扬","chinese":86,"maths":65},
{"sid":3,"name":"东方不败","chinese":95,"maths":88},
{"sid":4,"name":"布袋和尚","chinese":36,"maths":69},
{"sid":5,"name":"狄云","chinese":78,"maths":91}
];
for(let i=0; i<scores.length; i++) {
let score = scores[i];
document.write("<tr>");
document.write("<td>" + score.sid + "</td>");
document.write("<td>" + score.name + "</td>");
document.write("<td>" + score.chinese + "</td>");
document.write("<td>" + score.maths + "</td>");
document.write("</tr>");
}
</script>
</table>
</body>
</html>
```
上面的代码使用了HTML的`<table>`标签来创建表格,使用JavaScript的`for`循环来遍历成绩数组,根据数组中的数据创建表格行。每个学员的学号、姓名、语文成绩和数学成绩分别显示在表格中的不同列中。最终的效果如下所示:
学号 | 姓名 | 语文成绩 | 数学成绩
---|---|---|---
1 | 岳不群 | 66 | 78
2 | 风清扬 | 86 | 65
3 | 东方不败 | 95 | 88
4 | 布袋和尚 | 36 | 69
5 | 狄云 | 78 | 91
阅读全文