如何在表行中获取第一个单元格 [英] How Do I Get First Cell In Table Row
本文介绍了如何在表行中获取第一个单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨 -
我有一个动态创建的表,可以在按钮点击时加载更多元素。我还要尝试做的是当点击一行时该表中的任何位置,无论哪一行获取该行的第一个单元格中的值。我用我的代码一直得到第一行第一个单元格的第一个值。
这是javascript:
Hi -
I have a dynamically created table that loads more elements on button click. What I'm also trying to do is when any where in that table when a row is clicked no matter what row get the value in the first cell of that row clicked. I keep get the first value of the first row first cell with my code.
Here is the javascript:
$(".browseTable").click(function () {
var ptsID = $(this).find('td:first').text();
//var ptsID = $('td:first').text();
console.log(ptsID);
});
这是表格
Here is the table
<table id="displayMe" class="browseTable">
<tr>
<th>
ID
</th>
<th>
Image
</th>
<th>
Company
</th>
</tr>
<tbody>
</tbody>
</table>
推荐答案
( 。browseTable)。click(function(){
var ptsID =
(".browseTable").click(function () { var ptsID =
( this )。find(' td:first')。text();
// var ptsID =
(this).find('td:first').text(); //var ptsID =
(' td:first')。text();
console.log(ptsID);
});
('td:first').text(); console.log(ptsID); });
这是表格
Here is the table
<table id="displayMe" class="browseTable">
<tr>
<th>
ID
</th>
<th>
Image
</th>
<th>
Company
</th>
</tr>
<tbody>
</tbody>
</table>
这篇关于如何在表行中获取第一个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文