html显示数组内容,在html表中显示js数组

I have a javascript array and I want to show parts of it in HTML.

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

For example what html code would I use in the body to show a table of just the info from QR4 - the number and the country? There are other parts to the array so to show the whole QR4 array would be fine, but Id also like to know how to select specific parts

例如,我将在身体中使用什么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";

I have this code making a table in php using csv which works fine but I want it client side, not server side. A table like this would be fine...

我有这个代码在PHP中使用csv制作一个表,但是我希望它是客户端,而不是服务器端。像这样的桌子会很好......

echo "

$f = fopen("csv.csv", "r");

while (!feof($f) ) {

echo "

";

$line_of_text = fgetcsv($f);

echo "

" . $line_of_text[10] . "";

echo "

\n";

}

fclose($f);

echo "\n

";

?>

3 个解决方案

#1

1

Here is a really simple example of how you could do it.

这是一个非常简单的例子,说明如何做到这一点。

检查这个小提琴。

You have to pass an array to the function displayArrayAsTable(). You can then specify the range of the array to insert into the table, for example from 24 to 25 like you asked, otherwise all the array will be processed.

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

The function will return a table element you can then append where you find more appropriate, or tweak the function so that will always insert it for you where you want.

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

#2

1

To show all rows of the QR4 array in a HTML table use this:

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

IDCity

for(id in QR4)

{

document.write('

' + id + '' + QR4[id] + '');

}

To show specific elements from the Javascript array in a HTML table use this:

要在HTML表格中显示Javascript数组中的特定元素,请使用以下命令:

NumberCity

document.write('

' + QR4[24] + '' + QR4[25] + '');

As I suspect you want to combine the QR[24] and QR[25] elements in one row, that's what I did in my second code sample. But if that's the situation, your array structure isn't very logical.

因为我怀疑你想要将QR [24]和QR [25]元素组合在一行中,这就是我在第二个代码示例中所做的。但如果是这种情况,你的数组结构就不合逻辑了。

I gave you the code samples to select data from Javascript arrays and put them in HTML tables, now it's on you to use it the way you need it.. Because that isn't clear to me at all..

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

#3

0

Assuming you already have the table defined, you can use some simple DOM methods to add and delete rows.

假设您已经定义了表,可以使用一些简单的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];

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值