如何在点击事件中设置重绕功能?

时间:2019-04-25 11:39:29

标签: javascript jquery

我要计算具有许多选项的东西的价格,我使用jquery我编写了一个函数,该函数可以在我更改或单击时使用该函数进行计算?

      <script>
    $( document ).ready(function() {   $('.option_price3').change(function() {
            if($(this).is(":checked")) {
                var addition = $(this).val();
                basic_price = basic_price * addition ;
                $("#price_elo").html('<h1>'+basic_price+'<span id="SPAN_13"> € </span></h1>');
                return;
            }
            number_match = $(".pl-ns-value").val();
            basic_price = number_match * 2.99 ;
            if ($(".service_duo").val() == 'duo') {
                var old_basic_price = basic_price/2;
                basic_price = old_basic_price + basic_price;
                $("#price_elo").html('<h1>' + basic_price + '<span id="SPAN_13"> € </span></h1>');
            }else{
                $("#price_elo").html('<h1>' + basic_price + '<span id="SPAN_13"> € </span></h1>');
            }
        });
        });
</script>
<script>
    var prices = [
        13.90, 13.90, 13.90, 13.95, 15.90, 16.90, 17.90, 18.90, 19.90, 24.90, 27.90, 29.90, 33.90, 35.90, 38.90, 47.90, 51.90, 57.90, 59.90, 67.95, 129.90, 159.90, 169.90,
    ]

    function calculatePrice() {
        var price = 0;
        var depart = $("#depart_division option:selected").val() * 4 + $("#depart_subdivision option:selected").val() * 1;
        var destination = $("#destination_division option:selected").val() * 4 + $("#destination_subdivision option:selected").val() * 1;
        if (depart >= destination) {
            alert("Downgrading is not available");
        } else {

            for (i = depart; i < destination; i++) {
                price += prices[i];
            }
        }
        price = Math.round(price * 100) / 100;
        console.log(price);
        $("#price_elo").html('<h1>' + price + '<span id="SPAN_13"> € </span></h1>');
        return price;

    }
</script>

我想使用更改时返回的calculatePrice()执行它,并使用此函数返回它的价格来计算最终价格

0 个答案:

没有答案