我在网站上有英文和法文的表单,是否可以使用jquery验证插件根据语言显示正确的语言错误消息?
我尝试了一种基于url的方法,该方法有效,但仅显示一条“必需”消息,并且需要为要验证的每个表单项显示所有自定义消息。
jQuery:
var url = location.pathname;
if (url.indexOf("representative-fr.html") > -1) {
jQuery.extend(jQuery.validator.messages, {
required: "Ce champ est obligatoire."
});
} else {
jQuery.extend(jQuery.validator.messages, {
required: "This field is mandatory."
});
}
我要做什么:
if (url.indexOf("representative-fr.html") > -1) {
$.extend($.validator.messages, {
howToContact: "Please select a contact option", (this will be in french)
firstName: "Please enter your first name", (this will be in french)
lastName: "Please enter your last name", (this will be in french)
});
} else {
$.extend($.validator.messages, {
howToContact: "Please select a contact option",
firstName: "Please enter your first name",
lastName: "Please enter your last name",
});
}