<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document
</title>
<style>
table {
border-collapse:collapse;
width: 500px;
margin: 100px auto;
text-align: center;
}
thead th,
tbody td{
height: 30px;
border: 1px solid #333;
font-size: 14px;
font-family: serif;
}
thead th {
background-color: #ccc;
font-size: 16px;
font-weight: 800;
}
a {
text-decoration: none;
}
</style>
</head>
<body>
<div class="score_sheet">
<table cellspacing=0 >
<thead>
<tr>
<th>姓名
</th>
<th>成绩
</th>
<th>分数
</th>
<th>操作
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<script>
var datas = [{
name:'迪迪',
subject:'JS',
score:'100',
},{
name:'迪迪1',
subject:'JS',
score:'100',
},{
name:'迪迪2',
subject:'JS',
score:'100',
},{
name:'迪迪3',
subject:'JS',
score:'100',
},{
name:'迪迪4',
subject:'JS',
score:'98',
}
]
var tbody = document.querySelector('tbody');
for ( var i = 0; i < datas.length; i++) {
var tr = document.createElement('tr');
tbody.appendChild(tr);
for (k in datas[i]) {
var td = document.createElement('td');
tr.appendChild(td);
td.innerHTML = datas[i][k];
}
var td = document.createElement('td')
td.innerHTML = '<a href = "javascript:">删除</a>';
tr.appendChild(td);
}
var as = document.querySelectorAll('a');
for (var i = 0; i < as.length; i++) {
as[i].onclick = function() {
tbody.removeChild(this.parentNode.parentNode);
}
}
</script>
</body>
</html>
转载请注明原文地址: https://lol.8miu.com/read-23533.html