Jquery“$.preferCulture()”不可用/不可访问
我一直在尝试使用 Jquery 格式化区域(区域设置)特定数字、日期等。互联网上的不同教程中出现了相同的内容。代码如下:
<script type="text/javascript" >
$.preferCulture("de-DE"); //The method that causes culture specific formatting mainly
var price = $.format("3899.359","c");
$("#price").html(price);
var available = $.format(new Date(2011,12,23),"D");
$("#available").html(available);
</script>
http ://weblogs.asp.net/scottgu/archive/2010/06/10/jquery-globalization-plugin-from-microsoft.aspx
我已经下载了最新版本的Jquery但我在其中找不到 $.preferCulture()
方法。如果执行此代码,我会收到一条错误消息,指出不支持此方法。
我正在使用 Jquery 的 Globalize 插件来获得更多的国际化,但即使在这种情况下,Globalize.culture() 确实存在但不起作用。例如,如果我执行以下代码:
<script type="text/javascript">
jQuery(document).ready(function()
{
$("#btn1").click(function()
{
Globalize.culture("fr");
var num = Globalize.format(123456.456789,"n3");
//Globalize.culture("de-DE");
//var num = Globalize.formatNumber("123456.456789","c");
alert(num);
alert(Globalize.culture().name);
});
});
</script>
这将显示一个带有“en”值而不是“fr”的警报,并且数字也采用“en”区域设置格式。在使用 globalize.js 插件时,我还包含了 globalize.cultures.js 但没有成功。
I have been trying to format regional (locale) specific numbers, dates etc using Jquery. Same things comes up in different tutorials on the internet. A code something as follows:
<script type="text/javascript" >
$.preferCulture("de-DE"); //The method that causes culture specific formatting mainly
var price = $.format("3899.359","c");
$("#price").html(price);
var available = $.format(new Date(2011,12,23),"D");
$("#available").html(available);
</script>
http://weblogs.asp.net/scottgu/archive/2010/06/10/jquery-globalization-plugin-from-microsoft.aspx
I have downloaded the latest version of Jquery but I cannot find $.preferCulture()
method in it. If I execute this code, I receive an error that this method is not supported.
I am using Globalize plugin for Jquery to get some more internationalization but even in that case, Globalize.culture()
do exist but does not work. Say for example if I execute the following code:
<script type="text/javascript">
jQuery(document).ready(function()
{
$("#btn1").click(function()
{
Globalize.culture("fr");
var num = Globalize.format(123456.456789,"n3");
//Globalize.culture("de-DE");
//var num = Globalize.formatNumber("123456.456789","c");
alert(num);
alert(Globalize.culture().name);
});
});
</script>
This displays an alert with "en" value instead of "fr" and number is formatted in "en" locale too. While using globalize.js plugin, I have also included globalize.cultures.js but in vain.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最近遇到了类似的问题,结果证明它与我包含文化文件的方式有关。
请务必使用以下命令实际导入适当的区域性:
或
请记住,导入的区域性非常重要,例如,当您想要根据 fr-FR 格式化值时,您应该导入cultures.fr -FR.js,因为它确实有所作为。
我还必须指出,对于格式设置,您应该始终包含国家/地区信息,因为格式往往因国家/地区而异(即使对于相同语言)。
顺便提一句。在当前版本中,您还需要使用精确的区域性来翻译内容(通过
localize()
),因为它需要回退。真遗憾(但我将创建一个带有修复的拉取请求,所以请继续关注)。I recently had similar problem lately and it turned out to be related to how I included culture file.
Be sure to actually import appropriate cultures either with:
or
Please keep in mind, that it is really important what culture you are importing, for example when you want to want to format a value according to fr-FR, you should import cultures.fr-FR.js as it really makes a difference.
I also must point out that for formatting you should always include country information as formats tend to vary from country to country (even for the same language).
BTW. In current release, you also need to use precise culture for translating stuff (through
localize()
) as it want fall back. What a shame (but I will create a pull request with the fix, so stay tuned).