English 中文(简体)
得出与同一类的先辈的所有价值。
原标题:Find the sum of all values of spinners with same class

我有一组中继器:<代码><select>输入领域,我想找到它们的总和。 我用最容易的方法是使用舱位选择器,但并不储存在阵列中类似类别要素的<代码>val()。

是否有办法储存<代码><select>阵列中的所有数值,以便我能够找到所有价值的总和。

My not working code looks like this.

function calcPrice() {
     var price = $( .food ).val() || [];
}
$("select").change(calcPrice);
最佳回答

这可能是多余的,但可以使用rel=“nofollow”http://www.pengowork.com/workshop/jquery/calculation/calculation.plugin.htm

或者你可以简单地做:

var price = 0.0
$(".food ").each(function() { 
   price += +this.value
});
问题回答

您是否想澄清<代码>食物的内容? 它们是否投入了田? 否则,你可能希望使用<代码>$(......food ).text()。

类似于分级答案,但如果你想要保持实际阵列,你可以做到:

var prices = $.map($(".food"), function () {
   return +this.value;
});
var expenses = 0.0;
$(".expense").each(function() { 
      expenses += +this.value;
});
$("#expense-total").html(expenses);

基本上与支线相同,但它已经缺失;这可以 f。 还添加了jquery要素的例子,将最终价值推向一个总额领域。 由于我很少在50岁以下担任这种提名,我可以补充一下。

这里的商业开支:





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签