How to get the row index in a HTML table

前端 未结 4 386
抹茶落季
抹茶落季 2021-01-14 08:10

I\'m trying to update a database users table. I made an HTML table which contains the data of the users in my database. this HTML table contains 3 columns and in each row t

4条回答
  •  鱼传尺愫
    2021-01-14 08:51

    May be something like the code below will help you to get the required information.

    $("button").click(function () {
        var $row = $(this).parent().parent(); //tr
        var $columns = $row.find('td');
        var rowIndex = $row.index();
        var values = new Array();
        for (var i = 0; i < $columns.length - 1; i++) {
            var item = $columns[i];
            values.push($(item).children().val());
        }
        alert(JSON.stringify(values));
    });
    

    http://jsfiddle.net/X4mMw/

提交回复
热议问题