我有 3 个表,如下所示:
<table id="timbercamptable">
<tr>
<th>Production</th>
<th class="unitspertitle"></th>
<th class="unitspernexttile"></th>
</tr>
<tr>
<td>Base production</td>
<td class="currentunits"></td>
<td class="nextunits"></td>
</tr>
</table>
表的类和结构相同,但表 id 不同。我希望innerText
使用 JavaScript控制类的 。调用这些类的正确方法是什么,知道另一个表将具有 idsulphurpittable
和goldminetable
.
例如,我想改变innerText
的currentunits
定位在timbercamptable
您可以使用document.querySelector
来查询表基础上table id
,并class
在表格单元格中。
document.querySelector("#timbercamptable .currentunits").textContent = "100.00";
<table id="timbercamptable">
<tr>
<th>Production</th>
<th class="unitspertitle"></th>
<th class="unitspernexttile"></th>
</tr>
<tr>
<td>Base production</td>
<td class="currentunits"></td>
<td class="nextunits"></td>
</tr>
</table>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句