繁体   English   中英

如何获取的id属性 <td> 从 <tr> 在jQuery中?

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

请帮我解决一下这个。

而不是循环..我们是否有类似获取第一个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语句的选择器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'));
    });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM