我正在尝试在这里制作游戏,到目前为止,我仍然处于游戏的10%。它叫“SOS”熟悉吗?像tic tac toe但不是“X”&在5x5中“O”但“S”和“O”,并且使用javascript。现在我有一个可编辑的td's
<table id="myTable" border="1" style="border-collapse: collapse; width:30%;" cellpadding="8">
<!-- 1st row -->
<tr>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
</tr>
<!-- 2nd row -->
<tr>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
</tr>
<!-- 3rd row -->
<tr>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
</tr>
<!-- 4th row -->
<tr>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
</tr>
<!-- 5th row -->
<tr>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
</tr>
</table>
如果我在这个td中输入一个文本,我怎么能把它带到另一个td的campare?因为要在这个游戏中得分,我必须垂直,对角和水平形成单词SOS。请帮助:)谢谢Javascripters :)
example: consider this are td's. the 1st player inputs "S". The second player inputs "0". Then the 1st player again inputs "S". Then that's a score for player 1.
[S][O][S][ ][ ]
[ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ]
答案 0 :(得分:2)
使用data-x&amp;每个td上的data-y属性,如
bins="log"
现在,您可以访问给定i&amp; j为
<td data-x="0" data-y="0"> X/O </td>
<td data-x="0" data-y="1"> X/O </td>
...
...
<td data-x="4" data-y="4"> X/O </td>
我认为不需要使用$('td[data-x="' + i + '"][data-y="' + j + '"]').text()
$ - jQuery
如果您没有使用jQuery或使用普通的Javascript,那么让我们执行以下操作:
contenteditable=true
然后你可以访问i&amp; j为
<td id="x0y0"> X/O </td>
<td id="x0y1"> X/O </td>
...
...
<td id="x4y4"> X/O </td>