使用JQuery Validation插件,我编写了以下内容,但发现显示的是默认验证消息而不是我的自定义消息(我在其他验证中使用了常量,所以知道它有效!)。我错过了什么?
$("#pageform").validate();
$("input[id^=displayName]").each(function() {
$(this).rules("add", {
maxlength: AGHOSTMOBILEADMIN_VALIDATION.constants.displayNameMaxLength,
messages: {
maxLength: AGHOSTMOBILEADMIN_VALIDATION.format.displayName
}
});
});
$("input[id^=navigationLabel]").each(function() {
$(this).rules("add", {
maxlength: AGHOSTMOBILEADMIN_VALIDATION.constants.navigationLabelMaxLength,
messages: {
maxLength: AGHOSTMOBILEADMIN_VALIDATION.format.navigationLabel
}
});
});
答案 0 :(得分:1)
试试这个..
messages: {
maxLength: AGHOSTMOBILEADMIN_VALIDATION.format.navigationLabel
}
到
messages: {
maxlength: AGHOSTMOBILEADMIN_VALIDATION.format.navigationLabel
}
注意MaxLength更改为maxlength(L变为l)
所以完整的代码应该是
$("#pageform").validate();
$("input[id^=displayName]").each(function() {
$(this).rules("add", {
maxlength: AGHOSTMOBILEADMIN_VALIDATION.constants.displayNameMaxLength,
messages: {
maxlength: AGHOSTMOBILEADMIN_VALIDATION.format.displayName
}
});
});
$("input[id^=navigationLabel]").each(function() {
$(this).rules("add", {
maxlength: AGHOSTMOBILEADMIN_VALIDATION.constants.navigationLabelMaxLength,
messages: {
maxlength: AGHOSTMOBILEADMIN_VALIDATION.format.navigationLabel
}
});
});
这是工作代码