JQuery 验证国际化问题
如何更改以浏览器语言给出错误消息的 JQuery 验证插件。我的意思是,如果我在具有英语语言的浏览器上运行它,错误将是英语,或者如果浏览器的语言是土耳其语,错误消息也将是土耳其语(当然,我会以该语言定义消息,如果我没有根据浏览器的语言定义错误消息列表)
How can I change JQuery Validation plugin that gives error message at browser's language. I mean if I run it on a browser that has English language errors will be in English or if the browser's language is Turkish error messages will be Turkish too(of course I will define messages at that languages, also I should define a default language if I didn't define an error message list according to browser's language)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以看看 jquery 的本地化插件: http://keith-wood.name/localization.html
它允许根据浏览器定义的语言加载 javascript 文件。
jquery 验证插件附带本地化文件,可在以下地址获取: http://ajax .aspnetcdn.com/ajax/jquery.validate/1.9/localization/messages_##.js 其中 ## 是本地代码。
您可以做的是加载带有默认错误消息的验证插件,然后使用本地化插件加载特定于语言的错误消息。您甚至可以编写本地化的 js 文件,语法非常简单:
希望这有帮助!
You could have a look at the jquery's localisation plugin: http://keith-wood.name/localisation.html
It allows loading javascript files based on the browser's defined language.
The jquery validation plugin comes with localisation files available at this adress: http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/localization/messages_##.js where ## is the loc code.
What you can do is load the validation plugin with the default error messages and then use the localization plugin to load the language-specific error messages. You can even write your localized js file, syntax is pretty trivial:
Hope this helps !
Jquery 验证插件使用数组变量。我定义了不同的数组变量,如下所示:
我将浏览器的语言作为两个字符
,并调用变量:
所以它对我有用。
Jquery validation plugin works with an array variable. I defined different array variables as like:
I get browser's language as two character as like
and I call the variable of :
so it works for me.
以下是设置自定义验证消息的简单方法的建议:
1. 创建一个名称为 XX_Messages.ee.js 的 js 文件,语法为:
2.
注意:将XX_Messages.ee.js导入到要验证的html头中
3.
注意:
XX_Messages.ee.js
文件必须导入到您的头部html 在你的验证js之前。Here's a suggestion for a simple way to set your custom validation message:
1. Create a js file with XX_Messages.ee.js name with syntax:
2.
Note: import your XX_Messages.ee.js in html head where you want validation
3.
Note:
XX_Messages.ee.js
file must be import in head of your html before your validation js.