如何使用jQuery计算输入框的总价值 [英] How to calculate the total value of input boxes using jquery

查看:65
本文介绍了如何使用jQuery计算输入框的总价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入框列表,现在我需要使用以下命名约定pre [0],pre [1],pre [2]等来计算在输入框中输入的所有值的总和.

I have a list of input boxes, now 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.

使用Jquery可能吗?

Is this possible with Jquery and how?

推荐答案

这样的作品行吗?

var sum = 0;

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

^=属性以选择器开头.

这篇关于如何使用jQuery计算输入框的总价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆