获取表格中选定行的id -HTML [英] Get id of selected row in a table -HTML

查看:975
本文介绍了获取表格中选定行的id -HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

我使用以下脚本访问行点击事件

I am using following script to access row click event

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

     });
 });

但它不能正常工作。如何获取选定的行ID?任何想法?

But its not working.How can get selected row id .??Any ideas??

推荐答案

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

     });
 });

这篇关于获取表格中选定行的id -HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆