JQuery验证 - 在错误消息中显示字段名称

Mat*_*nya 1 jquery jquery-validate

显示错误消息时,JQuery验证插件使用该{number}格式作为传递给规则的参数的占位符.(例如this field must be between {0} and {1} characters)

但是,我无法找到一种方法,使用数组将字段名称传递给全局范围中的消息$.validator.messages.

而不是静态:

this field is required

我想传递类似的东西:

the {fieldname} field is required

在我的服务器端框架:attributeLaravel中,plcaheholder服务于此目的.这个插件是否支持此功能?

Aru*_*hny 6

您可以将函数作为消息值传递

$.validator.messages.required = function (param, input) {
    return 'The ' + input.name + ' field is required';
}
Run Code Online (Sandbox Code Playgroud)

演示:小提琴