How to get the row index in a HTML table

前端 未结 4 395
抹茶落季
抹茶落季 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:59

    You can use parents() function for the same.

    var tr = $(this).parents('tr');
    

    this would give your row on which button was clicked.

    
      
      
          
      
      
    
    
    
    $("button").click(function () {
        var $row = $(this).parents('tr:first');
    
        var txt = $row.find('input[type=text]').val();
        var salVal = $row.find('select:selected').val();
    
        alert(txt+' '+salVal);
    });
    

提交回复
热议问题