我有一個PHP動態生成一堆表格的文件,每個表格也有一個動態生成的行數。使用jQuery訪問動態生成的表格中的單元格
<?php foreach($trees as $tree): ?>
<div class="tree">
<table>
<thead>
<tr>
<th>Fruit</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<?php foreach($tree as $fruit => $fruitPrice) ?>
<tr>
<td><?php echo $fruit; ?></td>
<td><?php echo $fruitPrice; ?></td>
</tr>
<?php endforeach; ?>
<tr>
<td>Total:</td>
<td class="totalPrice"></td>
</tr>
</tbody>
<table>
</div>
<?php endforeach; ?>
一個結果表看起來是這樣的(但仍然會有接近於臺100):
<div class="tree">
<table>
<thead>
<tr>
<th>Fruit</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Apple</td>
<td>$1.99</td>
</tr>
<tr>
<td>Banana</td>
<td>$1.29</td>
</tr>
<tr>
<td>Peach</td>
<td>$2.25</td>
</tr>
<tr>
<td>Total:</td>
<td class="totalPrice"></td>
</tr>
</tbody>
<table>
</div>
我將如何使用jQuery總和值的訪問<td>
小號並在.totalPrice
中顯示總價格?
這張桌子在這裏變得刺激。
我試圖在一個循環內編寫一個循環,但無法讓它訪問正確的字段。
顯示你嘗試過什麼,所以人可以向你解釋你做了什麼錯誤。 – 2016-07-24 14:07:47