How do I get data from a table?

后端 未结 3 1038
一整个雨季
一整个雨季 2020-11-27 17:25

How do I pull data (string) from a column called "Limit" in a table ("displayTable") in Javascript?

var table = document.getElementById(\'         


        
3条回答
  •  时光说笑
    2020-11-27 18:06

    This is how I accomplished reading a table in javascript. Basically I drilled down into the rows and then I was able to drill down into the individual cells for each row. This should give you an idea

    //gets table
    var oTable = document.getElementById('myTable');
    
    //gets rows of table
    var rowLength = oTable.rows.length;
    
    //loops through rows    
    for (i = 0; i < rowLength; i++){
    
       //gets cells of current row
       var oCells = oTable.rows.item(i).cells;
    
       //gets amount of cells of current row
       var cellLength = oCells.length;
    
       //loops through each cell in current row
       for(var j = 0; j < cellLength; j++){
          /* get your cell info here */
          /* var cellVal = oCells.item(j).innerHTML; */
       }
    }
    

    UPDATED - TESTED SCRIPT

    A1 A2 A3
    B1 B2 B3

提交回复
热议问题