我需要从包含文本字段的表格单元中选取值。如何使用JavaScript从表格中获取单元格值?
在我来说,我得到这样的结果:
input type="text" name="test1" onchange="myFunction()
,但我想从一个文本字段的值。
我有这个功能。
function GetTableCells(){
var oTable = document.getElementById('cell_values');
//gets table
var rowLength = oTable.rows.length;
//gets rows of table
for (i = 0; i < rowLength; i++){
//loops through rows
var oCells = oTable.rows.item(i).cells;
//gets cells of current row
var cellLength = oCells.length;
for(var j = 0; j < cellLength; j++){
//loops through each cell in current row
var cellVal = oCells.item(j).innerHTML;
alert(cellVal);
} } }
是不是很容易的ID分配给每个以这种方式输入和检索它? 'document.getElementById(“inputID”)'? – oleq 2013-02-20 08:58:26