Get id of selected row in a table -HTML

后端 未结 2 545
挽巷
挽巷 2020-12-06 03:36

I have a table in my MVC application.I want to get the id of the selected row.I captured the click event of tr using jQuery. The table sample is shown below



        
相关标签:
2条回答
  • 2020-12-06 03:54

    You were almost there. Just access it directly:

    alert(this.id);
    
    0 讨论(0)
  • 2020-12-06 04:01
    $(document).ready(function () {      
         $('#resultTable tr').click(function (event) {
              alert($(this).attr('id')); //trying to alert id of the clicked row          
    
         });
     });
    
    0 讨论(0)
提交回复
热议问题