簡體   English   中英

語法錯誤:缺少:屬性后(jQuery驗證)

[英]Syntax error: missing : after property (jQuery validate)

我正在構建一套用於表單原型的jQuery驗證規則。

我的代碼出現JS錯誤。 Chrome瀏覽器抱怨該錯誤

[14:30:27.722] SyntaxError: missing : after property id

在代碼注釋中指定的位置。

這是代碼:

    $.validator.addMethod("regex", function(value, element, regexpr) {          
        return regexpr.test(value);
    }, "Entree invalide");

    $('#mainform').validate({
        rules: {
            form-nocivique: { //Chrome complains here
                required: true,
                digits: true
            },
            form-rue: "required",
            form-province: "required",
            form-codepostal: {
                required: true,
                regex: /([ABCEGHJKLMNPRSTVWXYZ]\d){3}/i
            }
        },
    });

知道為什么嗎?

您的屬性名稱(其中一些)是無效的標識符。

您可以引用它來解決問題:

   rules: {
        "form-nocivique": { //Chrome complains here
            required: true,
            digits: true
        },

您不能在JavaScript中使用-標識符; 這是一個令牌(“減號”運算符)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM