0

使用 jquery validate 插件时出现语法错误。我想定位类而不是字段名,这就是我使用以下语法的原因:

$("#myFormID").validate({        
    $('.optionSelectClass').rules("add", {
        required: true
    });       

    $('.optionSelectClass').messages("add", { 
        required: "Please select an option"    
    });

}); 

Firebug 控制台说丢失:在属性 id 之后

有任何想法吗?

4

1 回答 1

1

使用对象字面量语法定义对象时,不要;在每key: value对声明后添加:

{
    required: true
}

对象字面量通过逗号分隔的key: value对声明进行声明:

{
    required: true, // note the comma
    minLength: 4,   // note the comma
    maxLength: 10   // note _no_ comma; this will throw a SyntaxError in IE
}
于 2012-04-05T10:08:13.613 回答