gpt4 book ai didi

javascript - 从 HTML 创建数组

转载 作者:行者123 更新时间:2023-11-27 22:29:55 25 4
gpt4 key购买 nike

我有 4 个图表,每个图表在 html 中都有自己的 div。我试图找到将这些图表自动添加到数组的最佳方法,而无需在我更改图表及其 ID 时更新数组。

HTML:

<table id="dashboard" cellpadding="0" cellspacing="0">
<tr>
<td id="c1"><div class='chartLoadingOverlay'>Loading chart please be patient...</div></td>
<td id="c2"><div class='chartLoadingOverlay'>Loading chart please be patient...</div></td>

</tr>
<tr>
<td id="c3"><div class='chartLoadingOverlay'>Loading chart please be patient...</div></td>
<td id="c4"><div class='chartLoadingOverlay'>Loading chart please be patient...</div></td>
<!--<td id="BottomRight"><div class='chartLoadingOverlay'>Loading chart please be patient...</div></td>-->
</tr>
</table>

JS:

var arrOfChartContainers = ["c1","c2","c3","c4"];  <-- I want to automate this

最佳答案

DEMO

var x = $('.chartLoadingOverlay').closest('td').map(function () {
return this.id;
}).get();
console.log(x);

.map()

关于javascript - 从 HTML 创建数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18791030/

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