我创建了一个名为的类,该类具有属性之一。当用户按“添加”时,产品将被添加到名为 的数组中。因此,我尝试将数组中每个对象的总成本相加,以获得子总和。但它只将代码写出屏幕。producttotalcostproducts
var subtotal = subtotal();
function subtotal() {
if (products.length == 1) {
subtotal = totalcost;
return subtotal;
} else if (products.length > 1) {
for (i = 0; i < products.length; i++) {
subtotal += products[i].totalcost + products[i + 1].totalcost;
return subtotal;
}
}
}
蓝山帝景
慕村9548890
相关分类