jquery – 来自不同div的值与相同类的总和

我正在加载具有.totalprice类的动态div.最后,我想总结所有的.totalprice的价值.

解决方法

对于< div>内容
var sum = 0;
$('.totalprice').each(function(){
    sum += parseFloat($(this).text());  // Or this.innerHTML,this.innerText
});

你可以看到一个working example of this here

对于< input>元素(输入,复选框等):

var sum = 0;
$('.totalprice').each(function(){
    sum += parseFloat(this.value);
});

或者,如果要查找整数,可以使用parseInt()功能.

你可以see a working example of this here.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...