grid.children[i * 50 + j].style.backgroundColor = cell ? "#000" : "#fff";
<!DOCTYPE html>
<html>
<head>
<title>生命游戏</title>
<style>
#grid {
display: grid;
grid-template-columns: repeat(50, 10px);
grid-template-rows: repeat(50, 10px);
grid-gap: 1px;
background-color: #ddd;
}
.cell {
background-color: #fff;
</style>
</head>
<body>
<button id="start">开始</button>
<button id="stop">停止</button>
<button id="reset">重置</button>
<div id="grid"></div>
<script>