有时后提示信息要在执行了验证方法的回调之后才能确定该显示什么样的信息,这个时候用如下方法就不能达到要求:
$.addMethod('customFun', function (value, element, param) { console.log('This is test'); if (confirm('test')) { return true; } return false }, 'custom error message');这个时候需要在回调内部更改消息:
$.addMethod('customFun', function (value, element, param) {
var customMsg = '';
var result = true;
if (value.length < 5) {
customMsg = '长度太短';
result = false;
} else if (value.length > 20){
customMsg = '长度太长';
result = false;
}
$.validator.messages.customFun = customMsg;
return result;
});
http://blog.163.com/zhygpy%40126/blog/static/665230752013018074284/
本文介绍了一种在前端验证中自定义错误消息的方法。通过修改$.validator.messages.customFun属性,在执行验证逻辑的同时动态更新错误提示信息。
1392

被折叠的 条评论
为什么被折叠?



