javascript - 我如何从表的每一行中获取值并将它们存储在 js 数组中
问题描述
我有这段代码可以生成一个 html 表,我想在单击按钮时从行中获取所有数据并将其存储在 js 数组中。
<table cellpadding="0" cellspacing="0" width="25%" style="margin-top: 3em;" align="center">
<tr align="center">
<td> </td>
<td colspan="2" style="font-size:small;">Anualitat seleccionable</td>
</tr>
<tr align="center">
<td class="tau4"> </td>
<td class="tau4">Empleat</td>
<td class="tau4">Gestor</td>
</tr>
<logic:iterate id="i" name="anys_irpf" indexId="count">
<tr align="center" class="dadesAnys">
<td class="tau2" width="30%">${i.any}</td>
<td class="tau2" width="35%">
<c:choose>
<c:when test="${i.anyEmpleat == 1}">
<input type="checkbox" id="cbox1" value="cbox1" checked>
</c:when>
<c:otherwise>
<input type="checkbox" id="cbox1" value="cbox1">
</c:otherwise>
</c:choose>
</td>
<td class="tau2" width="35%">
<c:choose>
<c:when test="${i.anyGestor == 1}">
<input type="checkbox" id="cbox2" value="cbox2" checked>
</c:when>
<c:otherwise>
<input type="checkbox" id="cbox2" value="cbox2">
</c:otherwise>
</c:choose>
</td>
</tr>
</logic:iterate>
</table>
这是生成表格的代码。
解决方案
为该行的所有 td 标签提供相同的类名,因此当您单击按钮时,将获取类名的所有元素,并在 for 循环中添加该元素的所有值
推荐阅读
- azure-blob-storage - PowerApps:将集合更新为 csv 天蓝色 blob 存储
- java - 未找到 Java.time - JDK 13
- python - 更有效地替换 Pandas Dataframe 中多列的值
- amazon-s3 - 使用 createPresignedPost (nextjs api) 上传到 AWS S3--如何知道是否成功上传?
- wordpress - 键盘导航 - 轮播引导
- python - 扁平化字典时的问题
- python - 数字图案印刷
- apache-spark - Spark应用程序在一定间隔后从s3删除文件
- c++ - c++ 析构函数不能正常工作
- reactjs - 反应嵌套迭代器不返回值