How do I get current rowindex of a table using Javascript?

后端 未结 3 1397
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 13:08

Can I get current row index of a table in Javascript and can we remove the row of table with current Index that we got?

3条回答
  •  长发绾君心
    2021-01-21 13:57

    If you are using JQuery, use method .index()

    var index = $('table tr').index(tr);
    

    If no JQuery used, you can loop through all the TR element to find the matched TR.

    var index = -1;
    var rows = document.getElementById("yourTable").rows;
    for (var i=0;i

提交回复
热议问题