繁体   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