出于某种原因,我根本无法定义变量“total”...
我将它定义为 74,但由于某种原因它不想坚持..我做错了什么?提前致谢!
$(document).ready(function() {
    function getParameterByName(name)
    {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.search);
        if(results == null)
            return "";
        else
            return decodeURIComponent(results[1].replace(/\+/g, " "));
    }
    $(".tab-content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab-content:first").show(); //Show first tab content
    $('.question-form-submit').click(function(e) {
        e.preventDefault();
        var activeTab = '#'+$(this).attr('name');
        var activeClass = activeTab.substr(5);
        $("ul.tabs li").removeClass("active"); 
        $('ul li:nth-child('+activeClass+')').addClass("active"); //Add "active" class to selected tab
        $(".tab-content").hide(); //Hide all tab content
        $(activeTab).fadeIn(); //Fade in the active ID content
        $('.meter-value').removeClass('meter-width');
        switch (activeClass) {
            case '2' :
                $('.meter-value').attr('style', 'background-color: #9496c9; width: 46.5%;');
                break;
            case '3' :
                $('.meter-value').attr('style', 'background-color: #9496c9; width: 67%;');
                break;
            case '4' :
                $('.meter-value').attr('style', 'background-color: #9496c9; width: 100%;');
                break;
        }
        return false;
    });
    $('.quantity, .init_cost').change(function() {
        var row_id = $(this).attr('id');
        var row_number = row_id.substr(9);
        var item_cost = $('#cost_'+row_number).attr('value');
        var item_quantity = $('#quantity_'+row_number).attr('value');
        var final_cost = item_cost * item_quantity;
        $('#final_cost_'+row_number).val(final_cost).formatCurrency();;
    });
    $('.row input').each(function(index) {
        var row_id = $(this).attr('id');
        var row_number = row_id.substr(9);
        var item_cost = $('#cost_'+row_number).attr('value');
        var item_quantity = $('#quantity_'+row_number).attr('value');
        var final_cost = item_cost * item_quantity;
        $('#final_cost_'+row_number).val(final_cost).formatCurrency();;
    });
        var total = 0;
        $('.final_cost').each(function(index) {
            var final_cost = $(this).attr('value').substr(1);
            var total = total + final_cost;
            console.log(total);
        })
});