我showErrors
在 jquery 表单验证中使用在表单顶部显示错误消息。一次我想显示一条错误消息。在我的表格name,email,url and comment
中有四个可用的字段。如果用户直接单击提交按钮而不输入任何数据,则显示name
字段错误,但当用户关注字段时,email
它会覆盖两者的错误消息。name
email
jQuery :-
$(document).ready(function(){
$("form").validate({
messages: {
name: "Please specify your name.",
email: {
required: "We need your email address to contact you.",
email: "Your email address must be in the format of name@domain.com."
},
url: "A valid URL, please.",
comment: "Please enter your comment."
},
showErrors: function(errorMap, errorList) {
if(errorList.length) {
$("span").html(errorList[0].message);
}
}
});
});