获取表-HTML中所选行的ID

Nul*_*ter 6 html jquery

我在我的MVC应用程序中有一个表.我想获取所选行的id.我使用jQuery捕获了tr的click事件.表格样本如下所示

<table id="resultTable">
 <tr id="first">
  <td>c1</td>      
  <td>c2</td>      
 </tr>
 <tr id="second">
  <td>c3</td>      
  <td>c4</td>      
  </tr>    
</table>
Run Code Online (Sandbox Code Playgroud)

我正在使用以下脚本来访问行单击事件

 $(document).ready(function () {      
     $('#resultTable tr').click(function (event) {
          alert(this.); //trying to alert id of the clicked row          

     });
 });
Run Code Online (Sandbox Code Playgroud)

但它没有工作.如何获得选择的行ID.??任何想法?

ste*_*ecb 19

$(document).ready(function () {      
     $('#resultTable tr').click(function (event) {
          alert($(this).attr('id')); //trying to alert id of the clicked row          

     });
 });
Run Code Online (Sandbox Code Playgroud)


use*_*716 6

你快到了.只需直接访问它:

alert(this.id);
Run Code Online (Sandbox Code Playgroud)