从同一个表中按tr id读取td值
Read td values by tr id from the same table
我正试图根据tr-id读取表的值,但无法理解如何做到这一点。
// Id of the tr in question for example.row_17
var d =c["id"];
console.log(d);
// Here I can read all the td values, but I only want
// the ones inside the tr id = "row_17"
var cols =document.getElementById('report_table').getElementsByTagName('td'),
colslen = cols.length, i = -1; > while(++i < colslen)
{ console.log(cols[i].innerHTML);
}
由于您使用jQuery对其进行了标记,因此可以通过以下操作来完成:
var id = c["id"];
// Select only the row with id specified in 'id' and loop through all 'td's' of that row.
$("#" + id).find("td").each(function()
{
// Log the html content of each 'td'.
console.log($(this).html());
});
如果您只想要一个JavaScript解决方案(没有jQuery):
var id = c["id"];
var tds = document.querySelectorAll('#' + id + ' td');
for(var i = 0; i < tds.length; i++) {
console.log(tds[i].innerHTML);
}
演示
相关文章:
- Angular2-TypeError:无法读取属性'Id'(Typescript)中未定义的
- 在 JavaScript 中读取/加载 JSON,其中 'id' = 'x'
- 无法读取属性id成员路由
- "无法读取属性'id'未定义的“;解析工厂中声明的数组时
- 可以't让JavaScript将ID读取为变量名
- 我得到未捕获的类型错误:无法读取属性'选项'即使定义了元素id,也为null
- 使用cookie读取html对象的id
- 正在读取特定ID的JSON数据
- Angular JS TypeError:无法读取路由上未定义的属性“id”
- document.getElementById('id').selectedIndex 不读取索引,而是
- 无法读取 null 的属性“addEventListener”---但 ID 在那里
- 按 ID 读取元素
- 从 Windows Azure Mobile Services 中的读取请求中获取 ID
- 从同一个表中按tr id读取td值
- 读取JavaScript中的wicket id值
- 无法读取未定义的属性“id”
- 如何读取textbox's具有动态id
- 仅使用Javascript使用表行(
) id读取表单元格值( ) - 类型错误:不能读取属性'id'在nodejs中未定义的
- 从变量中读取 HTML “id” 属性