-2
我有一个表格和一个函数。 我可以采取单元格的参数。如何获得当前单元格的索引
我是新来的JS。请帮助找到当前单元格的索引。谢谢
function changePosition(currentCell) {
let top = currentCell.offsetTop
//need to find index of cell
}
<table class="square-table">
<tr>
<td onmouseover =
"changePosition(this)"></td>
<td onmouseover =
"changePosition(this)"></td>
<td onmouseover =
"changePosition(this)"></td>
<td onmouseover = function() {
"changePosition(this)"></td>
</tr>
</table>
我不明白这个问题。我会看到这不是一个有效的HTML表格。 – Goose
'function(){ changePosition(this)' 需要关闭'}' – fxlacroix
可能重复[获取内联onclick类元素的索引 - 纯js没有jQuery](https://stackoverflow.com/questions/) 44185632 /获取-指数的级元件与 - 直列的onclick纯-JS-NO-jquery的)。请参阅[我的回答](https://stackoverflow.com/a/44185902/1541563),其中提供了避免使用'onmouseover'属性的错误做法的方法。在表上使用'.addEventListener('mouseover',...)'来委派来自每个''的事件。 –