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

标签 javascript html css

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/

相关文章:

javascript - 试图将背景图像放在颜色之上

css - IE 7 & 8 溢出 :hidden problem

html - 为什么我的样式表不链接到索引?

javascript - 流: Use the types from connect to deduct the props' types?

javascript - 为什么我的 jquery 函数在 ajax 加载的页面中的 div 上不起作用

javascript - Event_Bus vue 变量访问单文件组件 Vue.js - Laravel Mix

javascript - onclick 函数在 JavaScript 中不起作用

javascript - Angular Material 日期时间选择器

css - 我应该在 <main> 标签上添加一个类吗?

html - 具有水平子导航的响应式下拉菜单