如何为两个 jquery ui 日期选择器设置语言
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9860214/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set languages for two jquery ui datepickers
提问by Vincent
I have two jquery ui datepickers in my page and I would like to apply a specific language for each one of them (let says german for one datepicker and italian for the other datepicker)
我的页面中有两个 jquery ui 日期选择器,我想为它们中的每一个应用一种特定的语言(让一个日期选择器说德语,另一个日期选择器说意大利语)
Now here is the problem: the last language file that is called apply its settings to all the datepickers (in this case, italian is applied in both inputs). I'm using the following code, what should I change to apply a specific language to each of the datepickers? thanks
现在问题来了:被调用的最后一个语言文件将其设置应用于所有日期选择器(在这种情况下,意大利语应用于两个输入)。我正在使用以下代码,我应该更改什么以将特定语言应用于每个日期选择器?谢谢
<script type="text/javascript" src="http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/jquery.ui.datepicker-de.js"></script>
<script type="text/javascript" src="http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/jquery.ui.datepicker-it.js"></script>
$(function(){
$.datepicker.setDefaults($.datepicker.regional['de']);
$( "#en" ).datepicker();
$.datepicker.setDefaults($.datepicker.regional['it']);
$( "#it" ).datepicker();
});
回答by Starx
This is how you do it: [Read Manual]
这是你的做法:[阅读手册]
$.datepicker.setDefaults($.datepicker.regional['de']);
// ^ first set a default locale
$("#en").datepicker($.datepicker.regional['en']);
// ^ then different locale for different
$("#it").datepicker($.datepicker.regional['it']);
回答by Rafay
回答by Chamika Sandamal
Use this code,
使用此代码,
$("#en").datepicker("option", $.datepicker.regional["de"]);?
$("#it").datepicker("option", $.datepicker.regional["it"]);?
回答by mindandmedia
according to the docs, you can just pass the regional as an option to datepicker()
, like so:
根据docs,您可以将区域作为选项传递给datepicker()
,如下所示:
$.datepicker.setDefaults( $.datepicker.regional[ "" ] );
$( "#datepicker" ).datepicker( $.datepicker.regional[ "fr" ] );
$( "#locale" ).change(function() {
$( "#datepicker" ).datepicker( "option",
$.datepicker.regional[ $( this ).val() ] );
});