How to tell which row number is clicked in a table?

前端 未结 6 513
陌清茗
陌清茗 2020-12-01 03:28

I have a table like the following:

6条回答
  •  隐瞒了意图╮
    2020-12-01 04:08

    This would get you the index of the clicked row, starting with one:

    $('#thetable').find('tr').click( function(){
    alert('You clicked row '+ ($(this).index()+1) );
    });
    
    
    111
    222
    333

    If you want to return the number stored in that first cell of each row:

    $('#thetable').find('tr').click( function(){
      var row = $(this).find('td:first').text();
      alert('You clicked ' + row);
    });
    

提交回复
热议问题