如何在使用Jquery点击TR时获取所有TD数据 [英] How can i get all TD data upon clicking on a TR with Jquery
本文介绍了如何在使用Jquery点击TR时获取所有TD数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个多行的表,我想在点击特定的ROW后获取所有的TD数据。
I am having a table with multiple rows and i want to get all the TD data after clicking on a particular ROW.
我的表是
<table>
<tr class="person">
<td class="id">1900</td>
<td class="name">John</td>
<td class="gender">Male</td>
</tr>
<tr class="person">
<td class="id">2000</td>
<td class="name">Pitt</td>
<td class="gender">Female</td>
</tr>
</table>
如何使用Jquery点击Row后,如何获取ID,姓名,性别。
How can i Get id, name, gender after clicking on Row using Jquery.
Ex: If i click on John Row i should get 1900, John, Male and same for Pitt also
谢谢
推荐答案
。您可以尝试find()方法而不是children()
Here is the solution. You may try find() method instead of children()
$(function(){
$('.person').click(function(){
var id = $(this).children('.id').text();
var name= $(this).children('.name').text();
var gender = $(this).children('.gender').text();
alert('Selected ID: ' + id + ', Name: ' + name + ', Gender: ' + gender);
});
});
这篇关于如何在使用Jquery点击TR时获取所有TD数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文