获取此行的第一个 TD

Get first TD of THIS row

本文关键字:第一个 TD 获取      更新时间:2023-09-26

相当容易,但我没有找到如何在线执行此操作。

我想要这个元素的第一个TD(行)

$(document).on("click", "#posTable tr", function() { 
    alert($(this).('td:first').text());
});

我试过了:

alert($(this).('td:first').text());
alert($('td:first', $(this).parents('tr')).text()));
您需要

使用 find() 来获取给定行中的第一个 td。您还可以在选择器中传递this作为上下文。

使用 find()

alert($(this).find('td:first').text());

使用 jQuery( selector [, context ] )

alert($('td:first', this).text());