zoukankan      html  css  js  c++  java
  • How do I get data from a data table in javascript?

    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

    var oTable = document.getElementById('myTable');
    //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
    <!--get your cell info here-->
    <!--var cellVal = oCells.item(j).innerHTML;-->
    }
    }
    UPDATED - TESTED SCRIPT

    <table id="myTable">
    <tr>
    <td>A1</td>
    <td>A2</td>
    <td>A3</td>
    </tr>
    <tr>
    <td>B1</td>
    <td>B2</td>
    <td>B3</td>
    </tr>
    </table>
    <script>
    var oTable = document.getElementById('myTable');
    //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
    <!--get your cell info here-->
    var cellVal = oCells.item(j).innerHTML;
    alert(cellVal);
    }
    }
    </script>

  • 相关阅读:
    Spring -- 自定义转换器
    Spring乱码问题解决方案
    Spring 声明式事务
    Spring -- IOC
    Spring--入门
    mybatis 二级缓存
    Mybatis 缓存失效的几种情况
    MyBatis深入浅出--入门
    【RF库Collections测试】Get From Dictionary
    【RF库Collections测试】Get Dictionary Values
  • 原文地址:https://www.cnblogs.com/zhangchenliang/p/3041016.html
Copyright © 2011-2022 走看看