简体   繁体   English

是什么导致错误“未捕获的TypeError:数字不是函数”

[英]What is causing the error “Uncaught TypeError: number is not a function”

I have an onchange event that updates a form, and in the updating process it calls a function to calculate shipping. 我有一个更新表单的onchange事件,并在更新过程中调用一个函数来计算运费。 I'm not sure why, but I'm getting the following error when I try to call the function: 我不确定为什么,但是当我尝试调用该函数时,我收到以下错误:

Uncaught TypeError: number is not a function

The function, shipping , looks like this: 功能, shipping ,看起来像这样:

function shipping( weight )
{
    var flat

    switch( weight )
    {
        case 1:
        case 2:
        case 3:
            flat = 32.00;
            break;

        case 4:
            flat = 18.50;
            break;

        case 5:
            flat = 15.80;
            break;

        case 6:
            flat = 14.00;
            break;

        case 7:
            flat = 12.71;
            break;

        case 8:
            flat = 11.75;
            break;

        case 9:
            flat = 11.00;
            break;

        case 10:
            flat = 10.40;
            break;

        case 11:
            flat = 9.91;
            break;

        case 12:
            flat = 9.50;
            break;

        case 13:
            flat = 9.15;
            break;

        case 14:
            flat = 8.86;
            break;

        case 15:
            flat = 8.86;
            break;

        case 16:
            flat = 8.38;
            break;

        case 17:
            flat = 8.18;
            break;

        case 18:
            flat = 8.00;
            break;

        case 19:
            flat = 7.84;
            break;

        case 20:
            flat = 7.70;
            break;

    } // switch

    var flat_fee = flat * weight;
    var mile_fee = distance * 0.90;

    var shipping_fee = flat_fee + mile_fee;
    simpleCart.shippingTest = shipping_fee;
    return shipping_fee;
} // shipping

I'm passing in 1 right now. 我现在正在传球1 The variable distance is coming from an ajax call that is completed before this function is run. 可变distance来自在运行此函数之前完成的ajax调用。 That function looks like this: 该函数如下所示:

function get_distance( zip )
{

    $.getJSON(
        'distance.php',
        { zip:zip },
        function(json)
        {
            distance = json 
        })

} // get_distance

I've checked to make sure the variable distance is set. 我已经检查过以确保设置了可变distance

The console says the uncaught type error is happing at the line where I call shipping(1) . 控制台说未被捕获的类型错误正在我称之为shipping(1)的线路上shipping(1) Any thoughts as to why that's happening? 有关为什么会发生这种情况的任何想法?

Are you using shipping as a variable anywhere? 您是否在任何地方使用shipping作为变量? Sounds like the function shipping is getting overwritten by using it as a variable with a numeric value of 1 . 听起来像使用数字值为1variable来覆盖function运输。

It's not in the code you posted (neither is the call to shipping(1) you mentioned). 它不在您发布的代码中(也不是您提到的shipping(1)号码shipping(1) )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是什么导致Uncaught TypeError:number不是函数? - What is causing Uncaught TypeError: number is not a function? setTimeout导致未捕获的TypeError:number不是函数 - setTimeout causing Uncaught TypeError: number is not a function 是什么导致此“未捕获的TypeError:无法调用未定义的方法”动画”错误? - What is causing this 'Uncaught TypeError: Cannot call method 'animate' of undefined' error? 未捕获的类型错误:$.number 不是 function - Uncaught TypeError: $.number is not a function 未捕获的TypeError:number不是函数 - Uncaught TypeError: number is not a function 未捕获的TypeError:number不是函数 - Uncaught TypeError: number is not a function 是什么导致此代码中的“未捕获的TypeError:非法调用”? - What is causing “Uncaught TypeError: Illegal Invocation” in this code? 是什么原因造成的:未捕获的类型错误:$ 不是函数? - What causes this: Uncaught TypeError: $ is not a function? 什么可能导致此错误:未捕获的 TypeError: r.clamp is not a function? - What could cause this error: Uncaught TypeError: r.clamp is not a function? 是什么导致我的“未捕获的TypeError:无法读取未定义的属性'toLowerCase'”错误? - What is causing my “Uncaught TypeError: Cannot read property 'toLowerCase' of undefined” error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM