导致错误的原因是“Uncaught TypeError:number is a function” [英] What is causing the error "Uncaught TypeError: number is not a function"

查看:73
本文介绍了导致错误的原因是“Uncaught TypeError:number is a function”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个更新表单的onchange事件,并且在更新过程中它调用一个函数来计算运费。我不确定为什么,但是当我尝试调用函数时出现以下错误:

I have an onchange event that updates a form, and in the updating process it calls a function to calculate shipping. I'm not sure why, but I'm getting the following error when I try to call the function:

未捕获TypeError:数字不是一个函数

函数 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

我传递 1 现在。变量 distance 来自在运行此函数之前完成的ajax调用。该函数如下所示:

I'm passing in 1 right now. The variable distance is coming from an ajax call that is completed before this function is run. 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.

控制台说未被捕获的类型错误在我打电话 shipping(1)的行上徘徊。有关为什么会发生这种情况的任何想法?

The console says the uncaught type error is happing at the line where I call shipping(1). Any thoughts as to why that's happening?

推荐答案

您使用运费作为变量在哪里?听起来像函数运输被覆盖为变量,数值为 1

Are you using shipping as a variable anywhere? Sounds like the function shipping is getting overwritten by using it as a variable with a numeric value of 1.

这不在您发布的代码中(也不是对发货的通话(1)你提到过。)

It's not in the code you posted (neither is the call to shipping(1) you mentioned).

这篇关于导致错误的原因是“Uncaught TypeError:number is a function”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆