Play Tic Tac Toe Online - Free Game
<!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')">
</div>
<div class="divTableCell" id="cell2" onclick="change('cell2')">
</div>
<div class="divTableCell" id="cell3" onclick="change('cell3')">
</div>
</div>
<div class="divTableRow">
<div class="divTableCell" id="cell4" onclick="change('cell4')">
</div>
<div class="divTableCell" id="cell5" onclick="change('cell5')">
</div>
<div class="divTableCell" id="cell6" onclick="change('cell6')">
</div>
</div>
<div class="divTableRow">
<div class="divTableCell" id="cell7" onclick="change('cell7')">
</div>
<div class="divTableCell" id="cell8" onclick="change('cell8')">
</div>
<div class="divTableCell" id="cell9" onclick="change('cell9')">
</div>
</div>
</div>
</div>
<script>
let turn = 'X';
function change(cell) {
if (document.getElementById(cell).innerHTML === ' ') {
document.getElementById(cell).innerHTML = turn;
turn = turn === 'X' ? 'O' : 'X';
}
}
</script>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/lnld 著作权归作者所有。请勿转载和采集!