我一直没有在JavaScript中编程,并且来自Java背景。我正在尝试在我的代码中使用事件处理程序,并且遇到问题。我有一个3x3表,因为我正在制作一个tic tac脚趾游戏,当用户点击其中一个框时,我想将按钮文本更改为X.所以我有我的表的HTML和按钮是表数据和点击相同功能时,我已分配了所有按钮。当一个按钮被点击时,我将它的ID发送给我的函数,然后从那里尝试使用这个ID参数来设置文本,但是现在只是没有发生,我有点困惑为什么不这样做。我也做了提示(paramID)和paramID是正确的,所以我不明白发生了什么事情。任何帮助将不胜感激!这可能是我在我身上所做的一些愚蠢的事情。我试过Firefox和Chrome ...更改表中的按钮的文本
这里是我的代码:
<table id="tictable" border="1"
<tr id="row1">
<td><button id="button1" type="button" onclick="actionPerformed(this.id)"</button></td>
<td><button id="button2" type="button" onclick="actionPerformed(this.id)"</button></td>
<td><button id="button3" type="button" onclick="actionPerformed(this.id)"</button></td>
</tr>
<tr >
<td><button id="button4" type="button" onclick="actionPerformed(this.id)"</button></td>
<td><button id="button5" type="button" onclick="actionPerformed(this.id)"</button></td>
<td><button id="button6" type="button" onclick="actionPerformed(this.id)"</button></td>
</tr>
<tr id="row3">
<td><button id="button7" type="button" onclick="actionPerformed(this.id)"</button></td>
<td><button id="button8" type="button" onclick="actionPerformed(this.id)"</button></td>
<td><button id="button9" type="button" onclick="actionPerformed(this.id)"</button></td>
</tr>
</table>
<script type="text/javascript">
function actionPerformed(paramID)
{
document.getElementById(paramID).value = "X";
}
</script>
你没有关闭你的开幕