Get Cell Location

前端 未结 4 1529
粉色の甜心
粉色の甜心 2020-12-03 15:33

So I have this table, and when I click on a td I would like to know where is that(which row and cell) without any attributes on the elements.

&l         


        
4条回答
  •  醉梦人生
    2020-12-03 16:25

    Well, When you have rowspan/colspan you can have a lot more fun, however, if the grid is regular, you can just determine your position from the index by doing:

    row = Math.floor(i / rows); 
    column = i % columns;
    

提交回复
热议问题