<分区>
不知道为什么不行。 jquery 没有把它们加起来。它只显示 00。我使用的是 rails 4。
# application.js
var sum = 0;
$('.sum1').each(function() {
sum += +$(this).text()||0;
});
$("#sum1_total").text(sum);
# view
<% @modification.boxes.each do |d| %>
<tr class="sum">
<td><%= best_in_place d, :shares, :type => :input, :class => :sum1 %></td>
</tr>
<% end %>
<tr>
<td><span id="sum1_total">00</span></td>
</tr>