我想从许多游乐设施中获得总数和平均值。现在我整天都被这个困住了,首先我尝试了它周围的跨度,但我想也许有一个数组更好,希望有人能帮助我解决缺失的部分。
示例:http: //jsbin.com/inapey/31/edit
<tbody id="rides">
<tr>
<td class="muted"><small>Mr.</small></td>
<td>John</td>
<td>Smith</td>
<!-- Every ride of this person -->
<td class="ride_km" style="display:none;">225,75</td>
<!-- Sum & Average of this person -->
<td class="ride_total_km"></td>
<td class="ride_average_km"></td>
</tr>
<tr>
<td class="muted"><small>Mrs.</small></td>
<td>Jane</td>
<td>Smith</td>
<!-- Every ride of this person -->
<td class="ride_km" style="display:none;">150,300</td>
<!-- Sum & Average of this person -->
<td class="ride_total_km"></td>
<td class="ride_average_km"></td>
</tr>
</tbody>
jQuery
$(document).ready(function(){
var total = 0;
$('#rides tr').each(function() {
var RidesKM = $(this).fin('.ride_km').html().split(",");
var arr = jQuery.makeArray(RidesKM);
alert(arr);
var SumKM = ???;
var AveKM = ???;
/* Total KM's */
$(this).find('.ride_total_km').html(SumKM);
/* Average KM's */
$(this).find('.ride_average_km').html(AveKM.toFixed(0));
});
});