模板字符串将学生数组动态渲染成表格tabel形式显示到页面
<script>
var students = [{
number: 1001,
name: 'jack',
score: 98,
gender: '男'
},
{
number: 1002,
name: 'rose',
score: 95,
gender: '女'
},
{
number: 1003,
name: '小丽',
score: 85,
gender: '女'
},
]
document.write(`
<table>
<tr>
<td>学号</td>
<td>名字</td>
<td>成绩</td>
<td>性别</td>
</tr>
`)
function hanshu() {
for (var key in students) {
document.write(`<tr>
<td>${students[key].number}</td>
<td>${students[key].name}</td>
<td>${students[key].score}</td>
<td>${students[key].gender}</td>
</tr>`)
}
document.write('</table>')
}
hanshu()
</script>