[英]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'))
}
您对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.