鉴于此表:
<table border="1" width="200" id="table1" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#CB2F7F">
<tr id="st_ppp">
<td width="60%" class="totalLabels">Price per piece</td>
<td width="39%" align="right" class="totalElements">unknown</td>
</tr>
<tr id="st_qty">
<td width="60%" class="totalLabels">Quantity</td>
<td width="39%" align="right" class="totalElements">unknown</td>
</tr>
<tr>
<td width="60%"> </td>
<td width="39%" align="right"> </td>
</tr>
<tr>
<td width="60%" class="subTotalLabel">Sub-Total:</td>
<td width="39%" align="right" class="subTotal">unknown</td>
</tr>
</table>
我想做类似下面的伪代码:
document.getElementById("st_ppp").[td whose class is totalElements].innerHTML="NewPrice";
document.getElementById("st_qty").[td whose class is totalElements].innerHTML="NewQty";
我也愿意接受对 HTML 进行任何其他更改的建议,这些更改将使 JS 更易于使用。