如何获取<td>从& lt; tr>在jQuery

how to get the id attribute of <td> from <tr> in jQuery?

本文关键字:lt jQuery tr td 何获取 获取      更新时间:2023-09-26

请帮帮我。

而不是循环…我们是否有像get第一个td或第二个td的id这样的东西?

示例:

"<tr class='test_point' id="+fileName+"><td><img src='"+ROOT_PATH+"/assets/diamond.png' /><td class='test_point_name' id="+test_point_id+">"+test_point
+"</td></tr>"

在这里通过ID获取tr

$(#fileName).each(function( index ){
  console.log( index + ": " + $(this).text() );
  //console.log("id_value: "+$(this).attr('id'));
  console.log("test_value: "+ $(this).find('td').attr('id'))
}   

通过索引获取项目的id,使用此。

$('#fileName').find('td')[0].id;

其中[0]表示第一,[1]表示第二…等等

您的each语句选择器有点偏离。你缺少引号:

$("#fileName").each(function( index ){

或者您想使用变量fileName

$("#" + fileName).each(function( index ){

在任何情况下,ID应该是唯一的。我猜你想使用你的tr s类:

$(".test_point").each(function( index ){
$('#your-tr-id-here').each(function() {
    $(this).children('td').each(function() {
        console.log('td ID: ' + $(this).attr('id'));
    });
});