[英]Syntax error: missing : after property (jQuery validate)
I am building a set of jQuery validate rules to be used for a form prototype. 我正在构建一套用于表单原型的jQuery验证规则。
I am getting a JS error with my code. 我的代码出现JS错误。 Chromes complains with the error
Chrome浏览器抱怨该错误
[14:30:27.722] SyntaxError: missing : after property id
at the location specified in the code comments. 在代码注释中指定的位置。
here is the code: 这是代码:
$.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
}
},
});
Any idea why? 知道为什么吗?
Your property names (some of them) are invalid identifiers. 您的属性名称(其中一些)是无效的标识符。
You can quote it to fix the problem: 您可以引用它来解决问题:
rules: {
"form-nocivique": { //Chrome complains here
required: true,
digits: true
},
You can't use -
in an identifier in JavaScript; 您不能在JavaScript中使用
-
标识符; it's a token (the "minus" operator). 这是一个令牌(“减号”运算符)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.