开发者

How to calculate the total value of input boxes using jquery

I have a list of input boxes, now 开发者_C百科I need to calculate the total of all values entered in input boxes with the following naming convention pre[0],pre[1],pre[2] etc.

Is this possible with Jquery and how?


Would something like this work?

var sum = 0;

$('input[name^="pre"]').each(function(){
    sum += parseFloat(this.value);
});

^= is the Attribute Starts With Selector.


I would do it like this

var sum = 0;

find("input[name*='pre']").each(function(index) {

sum = sum + this.val();

 })
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜