我尝试更改innerHTML 的所有内容都没有改变任何内容。没有 X 或 O,并且不会显示当前玩家的姓名。我一直在试图解决这个问题。我一直在寻找答案,据我所知,我所做的一切都是我应该做的。我今晚必须交出这个,我必须至少让基础知识发挥作用,这样我才能添加一些风格。
function start()
{
//alert("start");
player1name = prompt("Enter First Player's Name", "");
player2name = prompt("Enter Second Player's Name", "");
currentPlayer = player1name;
documet.getElementById("player").innerHTML = currentPlayer + "
choose a square.";
}
然后我就有了所有的 HTML。
<body onload="start()">
<!--HEADING AND PLAYER NAME-->
<h1>Tic Tac Toe</h1>
<!--DISPLAY NAME OF CURRENT PLAYER ON THEIR MOVE-->
<h2 id="player"></h2>
<!--TABLE-->
<div class="Table">
<!--FIRST ROW-->
<div class="Row">
<div class="Cell" id="1" onclick="playerMoved(this, 1)"></div>
<div class="Cell" id="2" onclick="playerMoved(this, 2)"></div>
<div class="Cell" id="3" onclick="playerMoved(this, 4)"></div>
</div>
<!--SECOND ROW-->
<div class="Row">
<div class="Cell" id="4" onclick="playerMoved(this, 8)"></div>
<div class="Cell" id="5" onclick="playerMoved(this, 16)"></div>
<div class="Cell" id="6" onclick="playerMoved(this, 32)"></div>
</div>
<!--THIRD ROW-->
<div class="Row">
<div class="Cell" id="7" onclick="playerMoved(this, 64)"></div>
<div class="Cell" id="8" onclick="playerMoved(this, 128)"></div>
<div class="Cell" id="9" onclick="playerMoved(this, 256)"></div>
</div>
</div>
最佳答案
在这条线上
documet.getElementById("player").innerHTML = currentPlayer + " choose a square.";
更正“文档”的拼写
关于javascript - Tic Tac Toe 无法更改innerHTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45271404/