Javascript获取表行TR的单元格 [英] Javascript get cells of a table row TR
问题描述
var as = document.getElementById('answers ['+ id +']');
var trs = as.getElementsByTagName(tr);
(var i in trs)
{...}
更新:如表所示。
在循环中,我想去同一个登录行,我尝试过:
var tds = trs [i] .getElementByTagName(td);
问题是在调试时我收到以下错误:
未捕获TypeError:Object#< HTMLTableRowElement>没有方法'getElementByTagName'。
如何进入trs的td?
其 getElementsByTagName
而不是 getElementByTagName
var as = document.getElementById('answers ['+ id +']');
for(var i = 0; i< as.rows.length; i ++){
var trs = as.getElementsByTagName(tr)[i];
var cellVal = trs.cells [0]
}
变量 cellVal
将引用第一个单元格
或< td>
类似地,通过增加索引或将其放在循环中将使所有单元格变为动态...
I want to manipulate table cells with javascript, and so far I managed to get into tr-s, by using:
var as = document.getElementById('answers['+id+']');
var trs = as.getElementsByTagName("tr");
for (var i in trs)
{ ... }
UPDATE: The as is the table.
Inside of the for cycle I wanted to go on the same login line and I have tried:
var tds = trs[i].getElementByTagName("td");
The problem is that on debugging I get the following error:
Uncaught TypeError: Object #<HTMLTableRowElement> has no method 'getElementByTagName' .
How could I get into the td-s of the tr-s?
its getElementsByTagName
and not getElementByTagName
var as = document.getElementById('answers['+id+']');
for(var i=0;i<as.rows.length;i++) {
var trs = as.getElementsByTagName("tr")[i];
var cellVal=trs.cells[0]
}
the variable cellVal
will give the reference to the first cell
or <td>
similarly do for all the cells by increasing the index or putting it in a loop would make it dynamic...
这篇关于Javascript获取表行TR的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!