2011-02-28 18 views
6

MVCアプリケーションにテーブルがあります。選択した行のIDを取得したいと思います.jQueryを使用してtrのclickイベントを取得しました。テーブルのサンプルでは、​​私は、行のクリックイベントにテーブル内の選択した行のIDを取得する-HTML

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

    }); 
}); 

しかし、そのworking.How選択得ることができない行IDにアクセスするには、次のスクリプトを使用しています

<table id="resultTable"> 
<tr id="first"> 
    <td>c1</td>  
    <td>c2</td>  
</tr> 
<tr id="second"> 
    <td>c3</td>  
    <td>c4</td>  
    </tr>  
</table> 

の下に示されている。??任意のアイデアを??

答えて

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

    }); 
}); 
6

あなたはほぼそこにいました。直接アクセスする:

alert(this.id); 
関連する問題