我有一个HTML和我的Tac脚趾字段。有几个onlick的
HTML (game.html):
<table class="nes-table is-bordered is-centered" id="tttpattern">
<tbody>
<tr>
<td class="square" id="0.0" onclick="gameController.putScore('0.0')"></td>
<td class="square" id="0.1" onclick="gameController.putScore('0.1')"></td>
<td class="square" id="0.2" onclick="gameController.putScore('0.2')"></td>
</tr>
<tr>
<td class="square" id="1.0" onclick="gameController.putScore('1.0')"></td>
<td class="square" id="1.1" onclick="gameController.putScore('1.1')"></td>
<td class="square" id="1.2" onclick="gameController.putScore('1.2')"></td>
</tr>
<tr>
<td class="square" id="2.0" onclick="gameController.putScore('2.0')"></td>
<td class="square" id="2.1" onclick="gameController.putScore('2.1')"></td>
<td class="square" id="2.2" onclick="gameController.putScore('2.2')"></td>
</tr>
</tbody>
</table>当我单击其中一个onclick时,我的代码在我的gameController.js中运行putScore函数。
在这个js中,我想检查我的payload中使用的payload是否与我从DB获得的player1 ID相同。
如果是这样的话,我的程序应该在我单击的方块中编写一个X。但事实并非如此。
有谁知道我怎么在广场上写X吗?
putScore函数(gameController.js)
putScore: function (option) {
gameModel.putScore(APP.route.param.gameID, {"field" : option}).then(function (data) {
if (APP.payload.user_id === data.player1) {
$("#" + data.field).text("X");
} else {
$("#" + data.field).text("O");
}
}).catch(function(e) {APP.logError(e)});
}我犯了什么错误吗?
我认为最重要的是:$("#" + data.field).text("X");
发布于 2020-01-17 15:09:25
是否有理由不使用本机选项,而不是使用jquery使其复杂化?
document.getElementById(option).innerHTML = "X";会在这里起作用吗?
https://stackoverflow.com/questions/59789345
复制相似问题