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>

  • 相关阅读:
    springboot+swagger生成api文档
    字符串格式化
    Navicat过期
    网页版的支付宝授权登录(vue+java)
    window,sts安装python
    PageHelper分页+排序
    android那些事之Bitmap、InputStream、Drawable、byte[]、Base64之间的转换关系
    两种解析JSON的方法
    蓝牙那些事之远程设备
    蓝牙那些事之状态监听
  • 原文地址:https://www.cnblogs.com/zhangchenliang/p/3041016.html
Copyright © 2011-2022 走看看