如何使用jQuery从html表行的第5个单元格中获取数据
我的代码运行良好:如何使用jQuery从html表行的第5个单元格中获取数据,jquery,html,html-table,Jquery,Html,Html Table,我的代码运行良好: var myValue = $(this).parents('tr:first').find('td:first').text(); 由于下面的代码不起作用,是否仍有办法让类似的东西工作: 如您所见,我正在尝试获取行中的第5列。使用: 如果$(此)引用的元素与您尝试选择的单元格位于同一行中,则可以使用以下方法稍微缩短该元素: 在jQuery中,:first是:eq(0)的快捷方式;没有名为:fifth的伪类。您可以执行以下操作: var myValue2 = $(this)
var myValue = $(this).parents('tr:first').find('td:first').text();
由于下面的代码不起作用,是否仍有办法让类似的东西工作:
如您所见,我正在尝试获取行中的第5列。使用:
如果$(此)
引用的元素与您尝试选择的单元格位于同一行中,则可以使用以下方法稍微缩短该元素:
在jQuery中,
:first
是:eq(0)
的快捷方式;没有名为:fifth
的伪类。您可以执行以下操作:
var myValue2 = $(this).parents('tr:first').find('td:nth-child(5)').text();
我认为你可以将两者结合起来:
var myValue3 = $(this).parents('tr:first td:nth-child(5)').text();
var myValue2 = $(this).closest('tr').find('td:eq(4)').text();
var myValue2 = $(this).parents('tr:first').find('td:nth-child(5)').text();
var myValue3 = $(this).parents('tr:first td:nth-child(5)').text();