我有各种输入,每一个通过数据属性不同的价格:如何总结从输入各种数据ATTR和价值
<%= f.number_field :item, class: "test", :data => {:price => '10.25'}
用户可以选择他们想要的项目数,所以我需要乘项目价格选择的项目数量。
$(document).ready(function() {
$(".test").on('change', function() {
a = $(".test").val() * $(".test").data("price") + "€";
$(".resultado").html(a);
});
});
这1个输入的伟大工程,但因为我有4个输入,每个都有不同的价格,我需要得到的总价格为他们的9。
<%= f.number_field :item, class: "test", :data => {:price => '10.25'} %>
<%= f.number_field :seconditem, class: "test", :data => {:price => '10'} %>
<%= f.number_field :thirditem, class: "test", :data => {:price => '10.75'} %>
<%= f.number_field :fourthitem, class: "test", :data => {:price => '10.50'} %>
基本上,我需要这样的:
A: Number of items * price of each item
Sum all of the "A" values
如何修改才能达到这个我的脚本/类?
非常感谢。
这完成了绝招!非常感谢! – Gibson