javascript - 未捕获的语法错误 : Unexpected token } debugging in Chrome

标签 javascript syntax-error curly-braces

我不明白发生了什么事。我正在使用 Chrome 来调试我的 js。它说意外}但它显然需要它。如果删除 },我会收到“Uncaught SyntaxError: Unexpected end of input”。

任何帮助表示赞赏。

$(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 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="72010702021d0006320106001b02175c111d1f" rel="noreferrer noopener nofollow">[email protected]</a> 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 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d0a3a5a0a0bfa2a490a3a4a2b9a0b5feb3bfbd" rel="noreferrer noopener nofollow">[email protected]</a> if you need assistance.");
    }
});

关于javascript - 未捕获的语法错误 : Unexpected token } debugging in Chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9900095/

相关文章:

haskell - Haskell中花括号的用途是什么?

javascript - 如何将对象作为参数传递并在构造函数内引用它

javascript - 触发后如何反转css动画?

javascript - 不推荐使用错误过滤器如何解决 vue.js 3 中的此错误

c++ - 使用花括号初始化临时聚合对象

objective-c - Objective-c 中的@interface 声明是否需要花括号?

javascript - 是否可以将 C 代码编译为 Javascript 代码?

c# - System.Data.SqlClient.SqlException : 'Incorrect syntax near ' ='.' on Datatable and object

javascript - 将 $scope 变量传递到带 Angular html 函数标记中

bash - “Syntax error”单词意外