gpt4 book ai didi

javascript - 需要将数组中的值插入到 html 表中

转载 作者:行者123 更新时间:2023-12-03 03:41:57 24 4
gpt4 key购买 nike

这次我在将值传递到我已经创建的 html 表中时遇到了一些问题。

这是我到目前为止的代码:

<table id="FinalTable">
<tr>
<td align="center">FECHA</td>
<th colspan="12" align="center">EVENTOS</th>
</tr>
<tr>
<th></th>
<td align="center">HORA INICIO</td>
<td align="center">SUMMARY</td>
<td align="center">DESCRIPTION</td>
<td align="center">LOCATION</td>
<td align="center">CREATED</td>
<td align="center">CREATOR_EMAIL</td>
<td align="center">STARTDATE</td>
<td align="center">START_DATE</td>
<td align="center">START_DATETIME</td>
<td align="center">START_TIMEZONE</td>
<td align="center">END_DATE</td>
<td align="center">END_DATETIME</td>
<td align="center">END_TIMEZONE</td>
</tr>
<tr>
<td align="center">(First date and so on)</td>
<td align="center">(Events detalized)</td>
</tr>
</table>
<br>

<script type="text/javascript" language="javascript">
document.write("<br><br><br>It's the end of the world as we know it!</br> </br></br>");


var ar = <?php echo json_encode($newarray) ?>;
for (var i = 0; i < ar.length; i++) {
for (var j = 0; j < ar[i]['Eventos'].length; j++) {
if(ar[i]['Eventos'][j].isArray !== 'undefined'){
document.write(
'<td><tr> ' + "fecha_inicio" + ' ' + ar[i]['Eventos'][j]['fecha_inicio'] + '</tr></td>' +
' ' + "hora_inicio" + ' ' + ar[i]['Eventos'][j]['hora_inicio'] +
' ' + "summary" + ' ' + ar[i]['Eventos'][j]['summary'] +
' ' + "description" + ' ' + ar[i]['Eventos'][j]['description'] +
' ' + "location" + ' ' + ar[i]['Eventos'][j]['location'] +
' ' + "created" + ' ' + ar[i]['Eventos'][j]['created'] +
' ' + "creator_email" + ' ' + ar[i]['Eventos'][j]['creator_email'] +
' ' + "startdate" + ' ' + ar[i]['Eventos'][j]['startdate'] +
' ' + "start_date" + ' ' + ar[i]['Eventos'][j]['start_date'] +
' ' + "start_datetime" + ' ' + ar[i]['Eventos'][j]['start_datetime'] +
' ' + "start_timezone" + ' ' + ar[i]['Eventos'][j]['start_timezone'] +
' ' + "end_date" + ' ' + ar[i]['Eventos'][j]['end_date'] +
' ' + "end_datetime" + ' ' + ar[i]['Eventos'][j]['end_datetime'] +
' ' + "end_timezone" + ' ' + ar[i]['Eventos'][j]['end_timezone'])
}
}
}

所以,基本上我不知道如何将 document.write 之后的所有值插入到表的字段中。

有人可以帮我吗?

非常感谢最亲爱的堆垛机!

最佳答案

表行需要位于 </table> 之前。 <td>需要在里面<tr> ,但你却反过来了。而且你的很多值都不在 <td> 中完全没有。

您应该用 PHP 完成整个事情。

<table id="FinalTable">
<tr>
<td align="center">FECHA</td>
<th colspan="12" align="center">EVENTOS</th>
</tr>
<tr>
<th></th>
<td align="center">HORA INICIO</td>
<td align="center">SUMMARY</td>
<td align="center">DESCRIPTION</td>
<td align="center">LOCATION</td>
<td align="center">CREATED</td>
<td align="center">CREATOR_EMAIL</td>
<td align="center">STARTDATE</td>
<td align="center">START_DATE</td>
<td align="center">START_DATETIME</td>
<td align="center">START_TIMEZONE</td>
<td align="center">END_DATE</td>
<td align="center">END_DATETIME</td>
<td align="center">END_TIMEZONE</td>
</tr>
<tr>
<td align="center">(First date and so on)</td>
<td align="center">(Events detalized)</td>
</tr>
<?php
foreach ($newarray as $el) {
foreach ($el['Eventos'] as $event) {
if (is_array($event)) {
echo "<tr>";
echo "<td>{$event['fecha_inicio']}</td>";
echo "<td>{$event['hora_inicio']}</td>";
// repeat for all fields in $event
echo "</tr>";
}
}
}
?>
</table>

关于javascript - 需要将数组中的值插入到 html 表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45573216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com