<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamic Data Table</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
box-sizing: border-box;
background-color: #f0f2f5;
}
.container {
max-width: 800px;
margin: 50px auto;
padding: 20px;
background-color: white;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
th, td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #007bff;
color: white;
}
tr:hover {
background-color: #f1f1f1;
}
</style>
</head>
<body>
<div class="container">
<h1>Dynamic Data Table</h1>
<button onclick="addRow()">Add Row</button>
<table id="dataTable">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Email</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<script>
function addRow() {
const table = document.getElementById('dataTable').getElementsByTagName('tbody')[0];
const row = table.insertRow();
const nameCell = row.insertCell(0);
const ageCell = row.insertCell(1);
const emailCell = row.insertCell(2);
nameCell.textContent = 'John Doe';
ageCell.textContent = '30';
emailCell.textContent = '[email protected]';
}
</script>
</body>
</html>
标签:const,表格,color,background,table,动态数据,border,row
From: https://blog.51cto.com/u_16215583/12032379