【问题标题】:how to read the values of a dynamic html table from a text file?如何从文本文件中读取动态 html 表的值?
【发布时间】:2013-09-19 06:08:43
【问题描述】:

我已经生成了一个动态 html 表,它借助 html 和 javascript 函数获取输入值,现在我想用表中的值绘制一个图表,这些值必须从外部文本插入到表中必须借助 javascript 上传到页面的文件,使用 PHPlot 的 php JSON 数组。

如何包含必须上传的文本文件以填充动态生成的 html 表的行和列?或

如何从文本文件中读取动态 html 表格的值?

HTML:

     <table id="contentTable" border="1" >
    <!-- Fill table programmatically -->

   <!-- include the .txt file which is present in the htdocs folder -->
    </table>

Javascript:

      function buildTable(val)
     {
   var myTable =document.getElementById("contentTable");
    var j=val;
var rows = [];
var cells = [];

   while (myTable.hasChildNodes()) {
    myTable.removeChild(myTable.lastChild);
   }


for( var i = 0; i < 1; i++ )
{
    rows[i] = myTable.insertRow(i);
    if(i%3==2)rows[i].addClass("every3rdrow");
    cells[i] = [];

    for( var x = 0; x < j ; x++ )
    {
        cells[i][x] =document.createElement((x==0)?"th":"td");
        cells[i][x].innerHTML = (x==0)?"<input>":"<input>";
        rows[rows.length - 1].appendChild(cells[i][x]);
    }
    }

    }
    buildTable();

我想用 phplot 绘制图形。

【问题讨论】:

    标签: javascript php html json getjson


    【解决方案1】:

    使用 jQuery get (http://api.jquery.com/jQuery.get/)

    $.get("whatever.txt", null, function(data, status, xhr){
       // append data which is content of whatever.txt
       $("table").append(data); // or whatever you want to do with it
    });
    

    【讨论】:

    • 我是 jquery 的新手,您能否详细说明上述答案以及我需要在函数数据、状态、xhr 中包含的内容以及 $("table") 是否对应于表 id ?
    猜你喜欢
    • 2020-05-04
    • 2017-04-03
    • 2015-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-18
    相关资源
    最近更新 更多