- 学习资源推荐 https://blog.csdn.net/qq_42813491/article/details/90213353
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>网格创建</title>
<style>
* {
margin: 0;
padding: 0;
}
table {
border-collapse: collapse;
}
td {
width: 20px;
height: 20px;
border: 1px solid #333;
}
</style>
</head>
<body>
</body>
<script>
let table = document.createElement('table');
for (let i = 0; i < 20; i++) {
(function() {
let tr = document.createElement('tr');
for (let i = 0; i < 20; i++) {
tr.appendChild(document.createElement('td'));
table.appendChild(tr);
}
document.querySelector("body").appendChild(table);
})()
}
</script>
</html>
效果图