今天编写项目的一个前段页面时,老是提示错误: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的朋友们有帮助。