Javascript 未捕获的SyntaxError:Chrome中意外的标记}调试

Javascript 未捕获的SyntaxError:Chrome中意外的标记}调试,javascript,syntax-error,curly-braces,Javascript,Syntax Error,Curly Braces,我不知道发生了什么事。我正在使用Chrome调试我的js。它说意外}但它显然需要它。如果删除},则会得到“未捕获的SyntaxError:输入的意外结束” 谢谢你的帮助 $(document).ready(function() { $("#payment-form").submit(function(event) { if (!$("input[name=agree]").is(":checked")) {

我不知道发生了什么事。我正在使用Chrome调试我的js。它说意外}但它显然需要它。如果删除},则会得到“未捕获的SyntaxError:输入的意外结束”

谢谢你的帮助

$(document).ready(function() {
            $("#payment-form").submit(function(event) {
                if (!$("input[name=agree]").is(":checked")) {
                        return false;
                    } else {
                        $('.submit-button').attr("disabled", "disabled");
                        // createToken returns immediately - the supplied callback submits the form if there are no errors
                        Stripe.createToken({
                          number: $('.card-number').val(),
                          cvc: $('.card-cvc').val(),
                          exp_month: $('.card-expiry-month').val(),
                          exp_year: $('.card-expiry-year').val()
                        }, stripeResponseHandler);
                        return false;
                        }
                    }
                }

            if (window.location.protocol === 'file:') {
                alert("stripe.js does not work when included in pages served over file:// URLs. Try serving this page over a webserver. Contact support@stripe.com if you need assistance.");
            }

上面的代码末尾缺少a}和)

上面的代码末尾缺少a}和)

您的大括号不匹配或缺失请尝试以下操作:

$(document).ready(function() {
    $("#payment-form").submit(function(event) {
        if (!$("input[name=agree]").is(":checked")) {
            return false;
        } else {
            $('.submit-button').attr("disabled", "disabled");
            // createToken returns immediately - the supplied callback submits the form if there are no errors
            Stripe.createToken({
                number: $('.card-number').val(),
                cvc: $('.card-cvc').val(),
                exp_month: $('.card-expiry-month').val(),
                exp_year: $('.card-expiry-year').val()
            }, stripeResponseHandler);
                return false;
        }
    });

    if (window.location.protocol === 'file:') {
        alert("stripe.js does not work when included in pages served over file:// URLs. Try serving this page over a webserver. Contact support@stripe.com if you need assistance.");
    }
});

您的花括号不匹配或缺失请尝试以下操作:

$(document).ready(function() {
    $("#payment-form").submit(function(event) {
        if (!$("input[name=agree]").is(":checked")) {
            return false;
        } else {
            $('.submit-button').attr("disabled", "disabled");
            // createToken returns immediately - the supplied callback submits the form if there are no errors
            Stripe.createToken({
                number: $('.card-number').val(),
                cvc: $('.card-cvc').val(),
                exp_month: $('.card-expiry-month').val(),
                exp_year: $('.card-expiry-year').val()
            }, stripeResponseHandler);
                return false;
        }
    });

    if (window.location.protocol === 'file:') {
        alert("stripe.js does not work when included in pages served over file:// URLs. Try serving this page over a webserver. Contact support@stripe.com if you need assistance.");
    }
});

哇!谢谢我盯着这个看太久了。谢谢我已经关注这个问题太久了。像这样孤立地诊断代码片段有点困难,但是在将代码粘贴到编辑器中并重新缩进后,它看起来是if(window.location)行结束传递给document.ready()的匿名函数之前的最后一个花括号。如果是这样的话,你需要一个“;”后,卷曲括号。如果“如果(窗口位置)”块应该位于匿名函数内部,那么这可能是您的问题-它似乎在匿名函数外部。正确缩进时会更清晰。像这样孤立地诊断代码片段有点困难,但在将代码粘贴到编辑器中并重新缩进后,它看起来是if(window.location)之前的最后一个花括号第行结束传递给document.ready()的匿名函数。如果是这种情况,则需要在该花括号后加“;”。如果“If(window.location)”块要在匿名函数内部,那么这可能是您的问题-它似乎在匿名函数外部。正确缩进后会更清晰。