【发布时间】:2016-07-24 14:05:56
【问题描述】:
我有一个文件,其中 php 动态生成一堆表,每个表也有动态生成的行数。
<?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>s 来汇总值并在 .totalPrice 中显示总价?
动态的表格让我很恼火。
我尝试在循环中编写循环,但无法让它访问正确的字段。
【问题讨论】:
-
展示你的尝试,以便人们向你解释你做错了什么。
标签: javascript php jquery