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