嗨,大家好,我的程序遇到问题,该问题说我没有方法“ toFixed”是什么意思或做什么来解决此问题?

这是我的javascript

<script type="text/javascript">
    $(document).ready(function(){

        $("#datepicker").kendoDateTimePicker({
            format: "yyyy-MM-dd HH:mm:ss"

        });

        $("#supplier_list").kendoComboBox();
        $(".code_select").kendoComboBox();

        //automatic computation in rows
        $('[id^=qty],[id^=price],#tin_number').on('change',function() {

            var index = this.id.match(/\d+/)[0];
            var qty = parseInt($('#qty'+index).val());
            var price = parseFloat($('#price'+index).val());
            var disc = $("#discount").val();
            var total = 0;

            $('#total'+index).val((qty * price ? qty * price : 0).toFixed(2));

            var total = 0;
            $('[id^=total]').each(function(index){
                total+=parseFloat($(this).val()?$(this).val():0);
            });

            var totalAll = $('#sum_of_total').val(total.toFixed(2));


            var vatable = 0;
            var vatable_amt = 0;
            var totalVat = 0;
            var computeDisc = 0;

            if($("#tin_number").val().length != 0){
                vatable = total / 1.12;
                vatable_amt = vatable * 0.12;
                totalVat = vatable + vatable_amt;

            }else{
                totalVat = total;

            }

            $('#vatable').val(vatable.toFixed(2));
            $("#vatable_amount").val(vatable_amt.toFixed(2));
            var gtotal = $("#gtotal").val(totalVat.toFixed(2));
            $("#total_amt_due").val(gtotal.toFixed(2));


//这是未捕获的错误行TypeError:Object [object object]没有方法'toFixed'

});

        $("#discount").on('change',function(){
            var totalSales = $("#gtotal").val();
            var discountedAmt = $("#discount").val();
            var computeTotalDisc = totalSales - discountedAmt;
            $("#total_amt_due").val(computeTotalDisc.toFixed(2));
        });

        //AUTO ASSIGN TO SUPPLIER INFO
        $('#supplier_list').bind('change', function(){
            var var_add_category ='<?php echo site_url("purchaseorder_controller/supplier_details"); ?>';
            $.ajax({
                type:'POST',
                url: var_add_category,
                data:{ id: $(this).val() },
                dataType:'json',
                success:function(d){

                    var bankname = d['bankname'];
                    var bankbranch = d['bankbranch'];

                    $("[name=spaddress]").val(d['spaddr']);
                    $("[name=tin]").val(d['sptinno']);
                    $("[name=contactperson]").val(d['pricontactname']);
                    $("[name=contactnumber]").val(d['sptelno']);
                    $("[name=bank]").val(bankname + ' - ' + bankbranch);
                    $("[name=account_name]").val(d['bankacctname']);
                    $("[name=account_no]").val(d['bankacctno']);

                }
            });
        });

        $("[id^=code]").on('change',function(){

            var index = this.id.match(/\d+/)[0];
            var validate = $('#code'+index).val();

            if(validate != ''){
                $("#qty"+index).removeAttr('readonly');
                $("#price"+index).removeAttr('readonly');
            }

        });

        $("[id^=code]").on('change',function(){

            var index = this.id.match(/\d+/)[0];
            var validate = $('#code'+index).val();

            if(validate == ''){
     $("#qty"+index).prop('readonly', true);
     $("#price"+index).prop('readonly', true);
 }


该怎么办请帮助我,谢谢你的帮助

最佳答案

gtotal是jQuery对象,不是数字?

var gtotal = $("#gtotal").val(totalVat.toFixed(2)); // returns jQuery object
$("#total_amt_due").val(gtotal.toFixed(2)); // that has no toFixed()


尝试:

var gtotal = totalVat.toFixed(2);

$("#gtotal, #total_amt_due").val(gtotal);

08-19 00:08