jquery动态验证规则忽略消息
使用JQuery验证插件,我编写了以下内容,但发现显示的是默认验证消息,而不是我的自定义消息(我在其他验证中使用了常量,所以要知道这是可行的!)。我错过了什么jquery动态验证规则忽略消息,jquery,jquery-validate,Jquery,Jquery Validate,使用JQuery验证插件,我编写了以下内容,但发现显示的是默认验证消息,而不是我的自定义消息(我在其他验证中使用了常量,所以要知道这是可行的!)。我错过了什么 $("#pageform").validate(); $("input[id^=displayName]").each(function() { $(this).rules("add", { maxlength: AGHOSTMOBILEADMIN_VALIDATION.constants.displayNameM
$("#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
}
});
});
试试这个
messages: {
maxLength: AGHOSTMOBILEADMIN_VALIDATION.format.navigationLabel
}
到
注释MaxLenth更改为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
}
});
});
这是工作代码
你能显示jsfiddle.net吗?你拼写错了
maxlength
。请注意,它的所有小写。该死的大小写敏感得到你每一次!
$("#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
}
});
});