SyntaxError-意外的输入结束

SyntaxError-Unexpected End of Input

我是新手。刚刚使用 Javascript 和 Jquery 和 Jquery 验证插件编写了一个简单的贷款审批申请。我遇到语法错误。 - 我匹配了开头和结尾的括号、大括号、分号和逗号,但不明白为什么它不起作用。 - 我尝试了不同的变体并不断收到错误(每次更改都指向不同的代码行)。 - 当我注释掉 jQuery 验证码时,它起作用了,所以问题一定出在 jQuery 验证码上。

下面是代码。当前在第 61 行出现 SyntaxError,这是最后一行反映 --> });

// JavaScript 文档 // 钻石贷款银行贷款申请

$(document).ready(function() {
    $("#submit").click(function() {
    var salary =  $("#salary").val();   // get salary
    var creditScore = $("#creditScore").val(); // get creditScore
    var monthsJob = $("#monthsJob").val(); // get months at job

    if  (salary >= 40000 && creditScore >= 600) {
        $("#decision").html("Your loan is approved!")
    }
    else if (salary >= 40000 && monthsJob >= 12) {
        $("#decision").html("Your loan is approved!")
    }
    else if (creditScore >= 600 && monthsJob >= 12) {
        $("#decision").html("Your loan is approved!")
    }
    else {
        $("#decision").html("Your loan is declined.")
    };
    return false;
    }); // closes submit.click  

    //     J Q U E R Y    V A L I D A T O R
    $("#loanApp").validate({
        rules: {
            salary: {
            required: true,
            rangelength: [4, 10],
            number: true
            },
            creditScore: {
            required: true,
            rangelength: [3, 3],
            number: true
            },
            monthsJob: {
            required: true,
            rangelength: [1, 3], 
            number: true
            },  
            messages: {
            salary: {
            required: "Please enter your salary.",
            rangelength: "Enter at least 4 numbers and up to 10.",
            number: "Enter numbers only."
            },
            creditScore: {
            required: "Please enter your Credit Score.",
            rangelength: "Credit Scores are 3 numbers long.",
            number: "Enter numbers only."
            },
            monthsJob: {
            required: "Please enter your months at current job.",
            rangelength: "Enter at least 1 number and up to 3.",
            number: "Enter numbers only."
            }
        } 
    }
});

您的 $(document).ready(... 最后缺少另一个 });。当前的是 $(#loanApp).validate(...

您的缩进有一点错误,导致您在 document.ready():

中漏掉了花括号
            }
        } 
    }
});

应该是:

                }
            } 
        }
    });
});

你在最后少了一个额外的 });。添加它,一切都应该正常工作。

$(document).ready(function() {
    $("#submit").click(function() {
    var salary =  $("#salary").val();   // get salary
    var creditScore = $("#creditScore").val(); // get creditScore
    var monthsJob = $("#monthsJob").val(); // get months at job

    if  (salary >= 40000 && creditScore >= 600) {
        $("#decision").html("Your loan is approved!")
    }
    else if (salary >= 40000 && monthsJob >= 12) {
        $("#decision").html("Your loan is approved!")
    }
    else if (creditScore >= 600 && monthsJob >= 12) {
        $("#decision").html("Your loan is approved!")
    }
    else {
        $("#decision").html("Your loan is declined.")
    };
    return false;
    }); // closes submit.click  

    //     J Q U E R Y    V A L I D A T O R
    $("#loanApp").validate({
        rules: {
            salary: {
            required: true,
            rangelength: [4, 10],
            number: true
            },
            creditScore: {
            required: true,
            rangelength: [3, 3],
            number: true
            },
            monthsJob: {
            required: true,
            rangelength: [1, 3], 
            number: true
            },  
            messages: {
            salary: {
            required: "Please enter your salary.",
            rangelength: "Enter at least 4 numbers and up to 10.",
            number: "Enter numbers only."
            },
            creditScore: {
            required: "Please enter your Credit Score.",
            rangelength: "Credit Scores are 3 numbers long.",
            number: "Enter numbers only."
            },
            monthsJob: {
            required: "Please enter your months at current job.",
            rangelength: "Enter at least 1 number and up to 3.",
            number: "Enter numbers only."
            }
        } 
    }
});

});//this is missing from your code, add this

末尾缺少一个 });

看起来 messagessalary 之间缺少的选项卡从视觉角度来看让您感到困惑。

$(document).ready(function() {
    $("#submit").click(function() {
    var salary =  $("#salary").val();   // get salary
    var creditScore = $("#creditScore").val(); // get creditScore
    var monthsJob = $("#monthsJob").val(); // get months at job

    if  (salary >= 40000 && creditScore >= 600) {
        $("#decision").html("Your loan is approved!")
    }
    else if (salary >= 40000 && monthsJob >= 12) {
        $("#decision").html("Your loan is approved!")
    }
    else if (creditScore >= 600 && monthsJob >= 12) {
        $("#decision").html("Your loan is approved!")
    }
    else {
        $("#decision").html("Your loan is declined.")
    };
    return false;
    }); // closes submit.click  

    //     J Q U E R Y    V A L I D A T O R
    $("#loanApp").validate({
        rules: {
            salary: {
            required: true,
            rangelength: [4, 10],
            number: true
            },
            creditScore: {
            required: true,
            rangelength: [3, 3],
            number: true
            },
            monthsJob: {
            required: true,
            rangelength: [1, 3], 
            number: true
            },  
            messages: {
                salary: {
                required: "Please enter your salary.",
                rangelength: "Enter at least 4 numbers and up to 10.",
                number: "Enter numbers only."
                },
                creditScore: {
                required: "Please enter your Credit Score.",
                rangelength: "Credit Scores are 3 numbers long.",
                number: "Enter numbers only."
                },
                monthsJob: {
                required: "Please enter your months at current job.",
                rangelength: "Enter at least 1 number and up to 3.",
                number: "Enter numbers only."
                }
            } 
        }
    });
});