您好我在这里使用Jquery验证为select选项定义用户定义所需的函数,
当值为-1时添加验证。但仍然不会将消息显示为请选择技术。请帮忙解释这段代码的错误
var reportValidator = $("#categoryForm").validate({
rules: {
reportType: "required",
productionLine:{
required: function(element) {
if( $("#productionLine").val()== "-1"){
return false;
}else{
return true;
}
}
},
userIds: "required"
},
errorElement: "span" ,
errorPlacement: function(error, element) {
if (element.attr("name") == "reportType"){
error.insertAfter("#reportError");
}else{
error.insertAfter(element);
}
},
messages: {
reportType: " Please Select Report Type",
productionLine : " Please Select Technology",
userIds: " Please Select User Ids"
}
});
答案 0 :(得分:0)
如果要在值为-1时进行验证,则必须更改返回值(true< - > false)