[轉]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
});
});
posted @ 2011-08-27 10:55  Athrun  阅读(547)  评论(0编辑  收藏  举报