大家好我无法找到解决方案;
<tr><td> Some Code here <input name="forwardings[nodes][amount][]" class="repeatingClass"> some more code here </td> </tr>
<tr><td> Some Code here <input name="forwardings[nodes][amount][]" class="repeatingClass"> some more code here </td> </tr>
<tr><td> Some Code here <input name="forwardings[nodes][amount][]" class="repeatingClass"> some more code here </td> </tr>
我需要总结所有的repeatClass值,当我从其中一个中集中注意力时,我尝试了类似的东西,但是无法处理这个;
$('.repeatingClass').focusout(function(){
var totalPoints = 0;
$('.repeatingClass').each(function(){
totalPoints += $('.repeatingClass').val();
});
alert(totalPoints);
});
我该怎么办? 问候
答案 0 :(得分:0)
输入中的空值被解释为字符串。因此,您应首先查看是否有值,如果有,请在致电parseInt
或parseFloat
$(function(){
$('.repeatingClass').focusout(function(){
var totalPoints = 0;
$('.repeatingClass').each(function(){
if ($(this).val())
totalPoints += parseInt($(this).val());
});
alert(totalPoints);
});
});
Here是一个小提琴