0

このスクリプトを使用して、スパン タグ間の価格をリアルタイムで計算しています。

$(document).ready(function () {
var form = $('.bestelformulier'),
    elements = form.find('[data-price], [type="radio"], [type="checkbox"], select'),
    totalEl = $('.totaalprijs');


//function to calculate total
var calculateTotal = function () {
    var total = 0;

    $.each(elements, function () {
        var field = $(this),
            newVal;

       // swith type omitted

        newVal = parseFloat(newVal);
        total += newVal;
    });

    totalEl.text(total);
};

// bind events
elements.on('change keyup', calculateTotal);
});

価格は次の場所に表示されます。

<span class="totaalprijs"></span>

どこに置く必要がありますか:

toFixed(2) 

価格が常に小数点以下 2 桁を表示するようにするには?

4

0 に答える 0