gpt4 book ai didi

javascript - 无法在浏览器中查看 div

转载 作者:行者123 更新时间:2023-11-28 01:21:04 25 4
gpt4 key购买 nike

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,现在不明白这是为什么,有什么想法吗?

最佳答案

您正在使用以下行删除它以查看元素。 display 属性指定是否/如何显示元素。 display: none; 使您的元素隐藏。

document.querySelector(".endgame").style.display = "none";

关于javascript - 无法在浏览器中查看 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51491384/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com