1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| <!DOCTYPE html> <html lang="en">
<head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> table { margin: 200px auto; }
table thead th, td { width: 150px; line-height: 40px; border: 1px solid rgb(0, 0, 0); background-color: rgb(197, 195, 195); font-size: 20px; text-align: center; }
table tbody tr td { background-color: rgb(255, 255, 255); } </style> </head>
<body> <table cellspacing="0"> <thead> <th>name</th> <th>subject</th> <th>score</th> <th>do</th> </thead> <tbody></tbody> </table> </body> <script> var datas = [ { name: 'qq', subject: 'math', score: 100 }, { name: 'ww', subject: 'chinese', score: 80 }, { name: 'ee', subject: 'pe', score: 170 }, { name: 'rr', subject: 'english', score: 90 }, ]
var tbody = document.querySelector('tbody') for (var i = 0; i < datas.length; i++) { var tr = document.createElement('tr') tbody.appendChild(tr) for (var 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 btn = document.querySelectorAll('a') for (var i = 0; i < btn.length; i++) { btn[i].onclick = function () { tbody.removeChild(this.parentNode.parentNode) } } </script>
</html>
|