[轉]jquery.validate 以alert方式显示错误方法
FROM : http://mangege.iteye.com/blog/1001984
$.validator.setDefaults({
submitHandler: function() { alert("submitted!");return false; }
});
$().ready(function() {
// validate signup form on keyup and submit
$("#reg_form").validate({
rules: {
/* input name 有 . 时加上引号 */
'mem.username': {
required: true,
minlength: 5
},
'mem.password': {
required: true,
minlength: 5
}
},
messages: {
'mem.username': {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
'mem.password': {
required: "Please provide a password2",
minlength: "Your password must be at least 5 characters long"
}
},
/* 重写错误显示消息方法,以alert方式弹出错误消息 */
showErrors: function(errorMap, errorList) {
var msg = "";
$.each( errorList, function(i,v){
msg += (v.message+"\r\n");
});
if(msg!="") alert(msg);
},
/* 失去焦点时不验证 */
onfocusout: false
});
});
申明
非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!
博文欢迎转载,但请给出原文连接。