var gameBoard;
const huPlayer = 'O';
const aiPlayer = 'X';
const winCombos = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[6, 4, 2]
]
const cells = document.querySelectorAll('.cell');
startGame();
function startGame() {
document.querySelector(".endgame").style.display = "none";
gameBoard = Array.from(Array(9).keys());
for (var i = 0; i < cells.length; i++) {
cells[i].innerText = '';
cells[i].style.removeProperty('background-color');
cells[i].addEventListener('click', turnClick, false);
}
}
function turnClick(square) {
turn(square.target.id, huPlayer)
}
function turn(squareId, player) {
gameBoard[squareId] = player;
document.getElementById(squareId).innerText = player;
}
td {
border: 2px solid #333;
height: 100px;
width: 100px;
text-align: center;
vertical-align: middle;
font-family: "Comic Sans MS", cursive, sans-serif;
font-size: 70px;
cursor: pointer;
}
table {
border-collapse: collapse;
position: absolute;
left: 50%;
margin-left: -155px;
top: 50px;
}
table tr:first-child td {
border-top: 0;
}
table tr:last-child td {
border-bottom: 0;
}
table tr td:first-child {
border-left: 0;
}
table tr td:last-child {
border-right: 0;
}
.endgame {
width: 200px;
top: 120px;
background-color: red;
position: absolute;
left: 50%;
margin-left: -100px;
padding-top: 50px;
padding-bottom: 50px;
text-align: center;
border-radius: 5px;
color: white;
font-size: 2em;
}
<!DOCTYPE html>
<html>
<head>
<title>tic tac toe</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<table>
<tr>
<td class="cell" id="0"></td>
<td class="cell" id="1"></td>
<td class="cell" id="2"></td>
</tr>
<tr>
<td class="cell" id="3"></td>
<td class="cell" id="4"></td>
<td class="cell" id="5"></td>
</tr>
<tr>
<td class="cell" id="6"></td>
<td class="cell" id="7"></td>
<td class="cell" id="8"></td>
</tr>
<div class="endgame">
<div class="text">Cant see this text</div>
</div>
<button onclick="startGame()">Replay</button>
</table>
<script type="text/javascript" src="script.js"></script>
</body>
</html>
大家好,我似乎无法通过班级残局查看我的div,现在不知道为什么会这样吗?
答案 0 :(得分:0)
您正在使用以下行,将其删除以查看元素。 display
属性指定是否/如何显示元素。 display: none;
隐藏了您的元素。
document.querySelector(".endgame").style.display = "none";
答案 1 :(得分:0)
从您的js中删除它意味着隐藏.endgame
div:
document.querySelector(".endgame").style.display = "none";
或在其他地方显示时使用:
document.querySelector(".endgame").style.display = "block";