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>

  • 相关阅读:
    常用控件
    ThinkJS 中的Logic层
    ctx简介
    小程序商城的配置文件初读
    webstorm快捷键
    vue.js入门
    前端技术俗语js
    vue环境中生成二维码
    第二章第一个项目——关于mime
    第二章第一个项目——package.json
  • 原文地址:https://www.cnblogs.com/zhangchenliang/p/3041016.html
Copyright © 2011-2022 走看看