<!DOCTYPE html>
<html>
  <head>
    <title>Play Tic Tac Toe Online - Free Game</title>
    <style>
      .divTable{
        display: table;
        width: 300px;
      }
      .divTableRow {
        display: table-row;
      }
      .divTableCell {
        display: table-cell;
        border: solid 1px #999999;
        width: 100px;
        height: 100px;
        text-align: center;
        font-size: 3em;
      }
    </style>
  </head>
  <body>
    <div>
      <h1>Tic Tac Toe</h1>
      <div class="divTable">
        <div class="divTableRow">
          <div class="divTableCell" id="cell1" onclick="change('cell1')">
            &nbsp;
          </div>
          <div class="divTableCell" id="cell2" onclick="change('cell2')">
            &nbsp;
          </div>
          <div class="divTableCell" id="cell3" onclick="change('cell3')">
            &nbsp;
          </div>
        </div>
        <div class="divTableRow">
          <div class="divTableCell" id="cell4" onclick="change('cell4')">
            &nbsp;
          </div>
          <div class="divTableCell" id="cell5" onclick="change('cell5')">
            &nbsp;
          </div>
          <div class="divTableCell" id="cell6" onclick="change('cell6')">
            &nbsp;
          </div>
        </div>
        <div class="divTableRow">
          <div class="divTableCell" id="cell7" onclick="change('cell7')">
            &nbsp;
          </div>
          <div class="divTableCell" id="cell8" onclick="change('cell8')">
            &nbsp;
          </div>
          <div class="divTableCell" id="cell9" onclick="change('cell9')">
            &nbsp;
          </div>
        </div>
      </div>
    </div>
    <script>
      let turn = 'X';
      function change(cell) {
        if (document.getElementById(cell).innerHTML === '&nbsp;') {
          document.getElementById(cell).innerHTML = turn;
          turn = turn === 'X' ? 'O' : 'X';
        }
      }
    </script>
  </body>
</html>
Play Tic Tac Toe Online - Free Game

原文地址: https://www.cveoy.top/t/topic/lnld 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录