这对我来说很奇怪。一些小的语法错误或其他东西。只需将两个变量的值相加并将它们附加到第三个变量。
var total = 0;
input.each(function(){
var thiis = $(this),
cost = thiis.attr('data-cost');
if (thiis.prop('checked')){
total = total + cost;
} else {
total = total - cost;
}
}
因此,如果cost = 5
和 输入等于 5。相反,我得到.checked
total
05
更新:
Word 是这些值不是整数,所以它们是附加的。不必做一些花哨的字符串整数翻转,有没有办法让我从一开始就将数据属性作为整数获取?
谢谢!