-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',...)'來委派來自每個''的事件。 –