我需要从具有文本字段的表单元格中获取值。

就我而言,我得到如下结果:

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);
        } } }

最佳答案

您可以执行以下操作:

var input = oCells[j].firstElementChild || oCells[j].firstChild;
var cellVal = input.value;

10-07 13:44
查看更多