-2

我的脚本:

$(function() {

    var base_price = 0;
    CalculatePrice();

    $(".math1").on('change', function(e) {
        CalculatePrice();
    });


    function CalculatePrice() {
        var base_cost = base_price;
        $(".c1").each(function(index) {
            var x = $(this).find('option:selected').data("price");
            base_cost += x;
        });
        $(".c2").each(function(index) {
            var y = $(this).find('option:selected').data("price");
            base_cost += y;
        });

        $("#price").text(base_cost*32);    
    }


});

该脚本将执行所有数据价格 + 彼此选定的数据价格,我希望它执行数据价格 * 每个选定的数据价格。我怎样才能做到这一点?

4

1 回答 1

3

您可以使用:

base_cost *= x;
base_cost *= y;

代替:

base_cost += x;
base_cost += y;
于 2014-05-12T16:32:15.053 回答