SyntaxError-Unexpected End of Input

时间:2016-10-26 13:56:56

标签: javascript jquery syntax-error jquery-validation-engine

我是新手。刚刚使用Javascript与Jquery和Jquery Validation插件编写了一个简单的贷款审批应用程序。我得到了一个SyntaxError。 - 我已经匹配了开头和结尾的花苞,花括号,分号和逗号,并且不明白为什么它不起作用。 - 我尝试了不同的变体并不断收到错误(每次更改都指向不同的代码行)。 - 当我注释掉jQuery Validation代码时,它可以正常工作,因此问题必须是jQuery Validation代码。

下面是代码。目前在第61行获取SyntaxError,这是反映的最后一行 - > });

// JavaScript文档 // DIAMOND LENDING BANK贷款申请

$(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."
            }
        } 
    }
});

4 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

你做了一个小缩进错误,导致你错过了document.ready()的大括号:

            }
        } 
    }
});

应该是:

                }
            } 
        }
    });
});

答案 2 :(得分:0)

你最后错过了额外的});。添加它,一切都应该正常。

$(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

答案 3 :(得分:0)

最后遗漏了});

看起来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."
                }
            } 
        }
    });
});