JS-”Undefined is not a function“错误

今天编写项目的一个前段页面时,老是提示错误:Undefined is not a function 仔细检查了一下,各个变量都进行了定义,不存在未定义的变量,最可能的情况排除了。然后就变得没头绪了,没法,还要硬着头皮去找错误,一句一句的执行,变量一个一个的检查。

 function AjaxGetProject(Pid, moneyWithfunding) {
            $.ajax({
                type: "post",
                data: { "Pid": Pid, "moneyWithfunding": moneyWithfunding },
                url: "/EverydayWin/GetEveryDayWinData/12",
                dataType: 'JSON',
                success: function (result) {
                    if (result == 0) {
                        alert("该配资方案不存在。")
                        $("#rateOpenLine").html(0)
                        $("#rateWarn").html(0)
                        $("#totalMoney").html(0)
                        $("#fee").html(0)
                    }
                    else if (result == 1) {
                        isInput = false;
                        $("#rateOpenLine").html("0")
                        $("#rateWarn").html(0)
                        $("#totalMoney").html(0)
                        $("#fee").html(0)
                    }
                    else {
                        $("#rateOpenLine").html((moneyWithfunding + (moneyDeposit * result["rateOpenLine"])).toFixed(0))
                        $("#rateWarn").html((moneyWithfunding + (moneyDeposit * result["rateWarn"])).toFixed(0))
                        $("#totalMoney").html((moneyWithfunding + moneyDeposit).toFixed(0))
                        $("#fee").html((moneyWithfunding * result["moneyRate"]).toFixed(2))
                    }
                }
            });
        }

在走到下面一句代码时发现moneyDeposit变量的类型竟然是string,而我实际想要的是int类型,上面的js执行代码时肯定要报错误。

        function GetDeposit() {
            $("input[name='moneyDeposit']").each(function () {
                var isCheck = $(this).attr("checked");
                if (isCheck && isCheck == "checked") {
                    moneyDeposit = $(this).next().text();
                }
            });
        }
修改moneyDeposit变量的定义,为它加了一个类型转换,最终执行成功。
 moneyDeposit = parseInt($(this).next().text());
错误出现的比较低级,希望对初学js的朋友们有帮助。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值