<table border=1>
<tr>
<td onclick='alert("行数:"+(this.parentNode.rowIndex+1)+"/n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentNode.rowIndex+1)+"/n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentNode.rowIndex+1)+"/n列数:"+(this.cellIndex+1))'>点我</td>
</tr>
<tr>
<td onclick='alert("行数:"+(this.parentNode.rowIndex+1)+"/n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentNode.rowIndex+1)+"/n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentNode.rowIndex+1)+"/n列数:"+(this.cellIndex+1))'>点我</td>
</tr>
<tr>
<td onclick='alert("行数:"+(this.parentNode.rowIndex+1)+"/n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentNode.rowIndex+1)+"/n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentNode.rowIndex+1)+"/n列数:"+(this.cellIndex+1))'>点我</td>
</tr>
</table>
<tr>
<td onclick='alert("行数:"+(this.parentNode.rowIndex+1)+"/n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentNode.rowIndex+1)+"/n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentNode.rowIndex+1)+"/n列数:"+(this.cellIndex+1))'>点我</td>
</tr>
<tr>
<td onclick='alert("行数:"+(this.parentNode.rowIndex+1)+"/n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentNode.rowIndex+1)+"/n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentNode.rowIndex+1)+"/n列数:"+(this.cellIndex+1))'>点我</td>
</tr>
<tr>
<td onclick='alert("行数:"+(this.parentNode.rowIndex+1)+"/n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentNode.rowIndex+1)+"/n列数:"+(this.cellIndex+1))'>点我</td>
<td onclick='alert("行数:"+(this.parentNode.rowIndex+1)+"/n列数:"+(this.cellIndex+1))'>点我</td>
</tr>
</table>
本文介绍了一种使用JavaScript为HTML表格中的单元格添加点击事件的方法。通过简单的代码实现,当用户点击表格中的任意单元格时,可以弹窗显示该单元格所在的行数和列数。这种方法适用于快速开发简单的用户交互功能。
1216

被折叠的 条评论
为什么被折叠?



