Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在html表中显示js数组_Javascript - Fatal编程技术网

Javascript 在html表中显示js数组

Javascript 在html表中显示js数组,javascript,Javascript,我有一个javascript数组,我想用HTML显示它的一部分 例如,我会在正文中使用什么html代码来显示仅包含QR4信息的表格-数字和国家?阵列还有其他部分,所以显示整个QR4阵列就可以了,但我也想知道如何选择特定部分 QR4[25] = "China"; QR4[24] = "39241000"; QR8[25] = "China"; QR8[24] = "39241000"; QR8L[25] = "China"; QR8L[24] = "39241000"; QR4L[2

我有一个javascript数组,我想用HTML显示它的一部分

例如,我会在正文中使用什么html代码来显示仅包含QR4信息的表格-数字和国家?阵列还有其他部分,所以显示整个QR4阵列就可以了,但我也想知道如何选择特定部分

QR4[25]  = "China";
QR4[24]  = "39241000";

QR8[25]  = "China";
QR8[24]  = "39241000";

QR8L[25] = "China";
QR8L[24] = "39241000";

QR4L[25] = "China";
QR4L[24] = "39241000";
我有这段代码使用csv在php中创建一个表,这很好,但我希望它是客户端的,而不是服务器端的。像这样的桌子就可以了

<?php
echo "<table>\n\n";
$f = fopen("csv.csv", "r");
while (!feof($f) )  {
    echo "<tr>";
    $line_of_text = fgetcsv($f);
            echo "<td>" .  $line_of_text[10] . "</td>";

    echo "<tr>\n";
}
fclose($f);
echo "\n</table>";
?>

要在HTML表格中显示QR4数组的所有行,请使用以下命令:

<table>
    <tr>
        <th>ID</th>
        <th>City</th>
    </tr>

    <script type="text/javascript">
    for(id in QR4)
    {
        document.write('<tr><td>' + id + '</td><td>' + QR4[id] + '</td></tr>');
    }
    </script>
</table>
<table>
    <tr>
        <th>Number</th>
        <th>City</th>
    </tr>

    <script type="text/javascript">
        document.write('<tr><td>' + QR4[24] + '</td><td>' + QR4[25] + '</td></tr>');
    </script>
</table>

身份证件
城市
用于(QR4中的id)
{
文件。写入(“”+id+“”+QR4[id]+“”);
}
要在HTML表中显示Javascript数组中的特定元素,请使用以下命令:

<table>
    <tr>
        <th>ID</th>
        <th>City</th>
    </tr>

    <script type="text/javascript">
    for(id in QR4)
    {
        document.write('<tr><td>' + id + '</td><td>' + QR4[id] + '</td></tr>');
    }
    </script>
</table>
<table>
    <tr>
        <th>Number</th>
        <th>City</th>
    </tr>

    <script type="text/javascript">
        document.write('<tr><td>' + QR4[24] + '</td><td>' + QR4[25] + '</td></tr>');
    </script>
</table>

数
城市
文件。书写(“”+QR4[24]+“”+QR4[25]+“”);
我怀疑您想要将QR[24]和QR[25]元素组合在一行中,这就是我在第二个代码示例中所做的。但如果是这种情况,那么您的数组结构就不太符合逻辑


我给了您一些代码示例,用于从Javascript数组中选择数据并将它们放入HTML表中,现在您可以按照需要的方式使用它们了。。因为我根本不清楚这一点。

假设已经定义了表,可以使用一些简单的DOM方法来添加和删除行

var table = document.getElementById("mytable");
for(i=0; i < QR4.length;i++) {
  var row = table.insertRow(table.rows.length);
  var cell = row.insertCell(0);
  cell.innerHTML = QR4[i];
}
var table=document.getElementById(“mytable”);
对于(i=0;i
下面是一个非常简单的示例,说明如何做到这一点

检查

必须将数组传递给函数
displayArrayTable()
。然后可以指定要插入到表中的数组的范围,例如,如您所要求的从24到25,否则将处理所有数组



该函数将返回一个表元素,然后您可以将其附加到您认为更合适的位置,或者调整该函数,以便始终为您插入所需的位置。

请注意,示例中有多个数组,而不仅仅是一个。据我所知,您希望显示
QR4
数组的所有元素?您希望该表看起来像什么?你能手工输入一个样本吗?数组:你做错了。变量名:你做错了。修复这两个并再次播放。我用csv制作了一个数组。让这个展示客户端的最好方法是什么?我不是停留在数组或变量名上,但这似乎是建议的方法…要更改哪个id?全部还是部分?我不明白你的问题,但我已经用更多的信息编辑了我的文章。这是很好的操作!谢谢([24]){document.write('+id++'+QR4[id]+'>)}document.write的另一个代码也是如此。将内容插入DOM的方法真的很糟糕,你应该使用
createElement
appendChild
。在我看来,你应该使用Javascript库来做这些事情,但我这样做的目的是希望他理解Javascript中循环和读取数组数据的工作方式。当我运行这个程序时,我在表的底部得到了新的数字24和25。如何输出数据而不是数组号,我更希望数据作为表中的第二列而不是第二行,因此数据是垂直的。当我问q时,我想我没有意识到这一点。有没有一种方法可以将它集成为向现有表中添加一列。我正在使用这段代码,但它添加了空列。我对于(i=0;i