大家好我试图将不同的jquery-ui datepicker选项组合成一个函数我可以从语言中获得大部分脚本工作appart我有所有il8n文件,我使用select元素来更改值但是没有似乎工作可以任何人告诉我我做错了什么
<script>
$(function() {
$.datepicker.setDefaults( $.datepicker.regional[ "" ] );
$( "#from" ).datepicker({
defaultDate: "+4w",
changeMonth: true,
numberOfMonths: 3,
showButtonPanel: true,
showOn: "button",
buttonImage: "../images/calendar.gif",
buttonImageOnly: true,
minDate:"+1d",
dateFormat:"yy/mm/dd",
showAnim:"bounce",
onSelect: function( selectedDate ) {
$( "#from" ).datepicker( $.datepicker.regional[ "en-GB" ] );
$( "#locale" ).change(function() {
$( "#from" ).datepicker( "option",
$.datepicker.regional[ $( this ).val() ] );
});
}
});
$( "#to" ).datepicker({
defaultDate: "+2w",
changeMonth: true,
numberOfMonths: 3,
showButtonPanel: true,
showOn: "button",
buttonImage: "../images/calendar.gif",
buttonImageOnly: true,
minDate:"+1d",
dateFormat:"yy/mm/dd",
showAnim:"bounce",
onSelect: function( selectedDate ) {
$( "#to" ).datepicker( $.datepicker.regional[ "en-GB" ] );
$( "#locale" ).change(function() {
$( "#to" ).datepicker( "option",
$.datepicker.regional[ $( this ).val() ] );
});
}
});
});
</script>
答案 0 :(得分:3)
我已经尝试了下面编写的代码(从您的代码中采用)并且它有效。也许你忘了为每种语言都包含jquery javascript?我只包括三种语言(例如法语)作为例子。此外,我有选择选项触发语言的更改事件,而不是触发onSelect。
我也试过你把它放到一个函数中的版本,除了因为它触发选择它必须先选择一个日期才能开始工作,然后是一个语言。
第一个版本(在一个函数中有效但在首次选择日期之前不会以语言显示的问题):
<html><head><title>Test1</title>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<link type="text/css" href="css/ui-lightness/jquery-ui-1.8.18.custom.css" rel="Stylesheet" />
<script type="text/javascript" src="js/jquery-ui-1.8.18.custom.min.js"></script>
<script type="text/javascript" src="jquery.ui.datepicker-fr.js"></script>
<script type="text/javascript" src="jquery.ui.datepicker-ar.js"></script>
<script type="text/javascript" src="jquery.ui.datepicker-af.js"></script>
<script type="text/javascript" src="jquery.ui.datepicker-en-GB.js"></script>
</head><body>
<script type="text/javascript">
$(function() {
$.datepicker.setDefaults( $.datepicker.regional[ "" ] );
$( "#from" ).datepicker({
defaultDate: "+4w",
changeMonth: true,
numberOfMonths: 3,
showButtonPanel: true,
showOn: "button",
minDate:"+1d",
dateFormat:"yy/mm/dd",
showAnim:"bounce",
onSelect: function( selectedDate ) {
$( "#from" ).datepicker( $.datepicker.regional[ "en-GB" ] );
$( "#locale" ).change(function() {
$( "#from" ).datepicker( "option",
$.datepicker.regional[ $( this ).val() ] );
});
}
});
});
</script>
<p>Date: <input type="text" id="from"/>
<select id="locale">
<option value="af">Afrikaans</option>
<option value="sq">Albanian (Gjuha shqipe)</option>
<option value="ar-DZ">Algerian Arabic</option>
<option value="ar">Arabic (‫(لعربي</option>
<option value="hy">Armenian (Հայերեն)</option>
<option value="az">Azerbaijani (Azərbaycan dili)</option>
<option value="eu">Basque (Euskara)</option>
<option value="bs">Bosnian (Bosanski)</option>
<option value="bg">Bulgarian (български език)</option>
<option value="ca">Catalan (Català)</option>
<option value="zh-HK">Chinese Hong Kong (繁體中文)</option>
<option value="zh-CN">Chinese Simplified (简体中文)</option>
<option value="zh-TW">Chinese Traditional (繁體中文)</option>
<option value="hr">Croatian (Hrvatski jezik)</option>
<option value="cs">Czech (čeština)</option>
<option value="da">Danish (Dansk)</option>
<option value="nl-BE">Dutch (Belgium)</option>
<option value="nl">Dutch (Nederlands)</option>
<option value="en-AU">English/Australia</option>
<option value="en-NZ">English/New Zealand</option>
<option value="en-GB">English/UK</option>
<option value="eo">Esperanto</option>
<option value="et">Estonian (eesti keel)</option>
<option value="fo">Faroese (føroyskt)</option>
<option value="fa">Farsi/Persian (‫(فارسی</option>
<option value="fi">Finnish (suomi)</option>
<option value="fr" selected="selected">French (Français)</option>
<option value="fr-CH">French/Swiss (Français de Suisse)</option>
<option value="gl">Galician</option>
<option value="ge">Georgian</option>
<option value="de">German (Deutsch)</option>
<option value="el">Greek (Ελληνικά)</option>
<option value="he">Hebrew (‫(עברית</option>
<option value="hi">Hindi (हिंदी)</option>
<option value="hu">Hungarian (Magyar)</option>
<option value="is">Icelandic (Õslenska)</option>
<option value="id">Indonesian (Bahasa Indonesia)</option>
<option value="it">Italian (Italiano)</option>
<option value="ja">Japanese (日本語)</option>
<option value="kk">Kazakhstan (Kazakh)</option>
<option value="km">Khmer</option>
<option value="ko">Korean (한국어)</option>
<option value="lv">Latvian (Latvieöu Valoda)</option>
<option value="lt">Lithuanian (lietuviu kalba)</option>
<option value="lb">Luxembourgish</option>
<option value="mk">Macedonian</option>
<option value="ml">Malayalam</option>
<option value="ms">Malaysian (Bahasa Malaysia)</option>
<option value="no">Norwegian (Norsk)</option>
<option value="pl">Polish (Polski)</option>
<option value="pt">Portuguese (Português)</option>
<option value="pt-BR">Portuguese/Brazilian (Português)</option>
<option value="rm">Rhaeto-Romanic (Romansh)</option>
<option value="ro">Romanian (Română)</option>
<option value="ru">Russian (Русский)</option>
<option value="sr">Serbian (српски језик)</option>
<option value="sr-SR">Serbian (srpski jezik)</option>
<option value="sk">Slovak (Slovencina)</option>
<option value="sl">Slovenian (Slovenski Jezik)</option>
<option value="es">Spanish (Español)</option>
<option value="sv">Swedish (Svenska)</option>
<option value="ta">Tamil (தமிழ்)</option>
<option value="th">Thai (ภาษาไทย)</option>
<option value="tj">Tajikistan</option>
<option value="tr">Turkish (Türkçe)</option>
<option value="uk">Ukranian (Українська)</option>
<option value="vi">Vietnamese (Tiếng Việt)</option>
<option value="cy-GB">Welsh/UK (Cymraeg)</option>
</select></p>
</body></html>
第二个版本(不是在一个功能中,也起作用,似乎对我更好,因为你不必选择日期来改变语言):
<html><head><title>Test1</title>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<link type="text/css" href="css/ui-lightness/jquery-ui-1.8.18.custom.css" rel="Stylesheet" />
<script type="text/javascript" src="js/jquery-ui-1.8.18.custom.min.js"></script>
<script type="text/javascript" src="jquery.ui.datepicker-fr.js"></script>
<script type="text/javascript" src="jquery.ui.datepicker-ar.js"></script>
<script type="text/javascript" src="jquery.ui.datepicker-af.js"></script>
</head><body>
<script type="text/javascript">
$(function() {
$.datepicker.setDefaults( $.datepicker.regional[ "" ] );
$( "#from" ).datepicker({
defaultDate: "+4w",
changeMonth: true,
numberOfMonths: 3,
showButtonPanel: true,
showOn: "button",
minDate:"+1d",
dateFormat:"yy/mm/dd",
showAnim:"bounce"
});
$( "#from" ).datepicker( $.datepicker.regional[ "en-GB" ] );
$( "#locale" ).change(function() {
$( "#from" ).datepicker( "option",
$.datepicker.regional[ $( this ).val() ] );
});
});
</script>
<p>Date: <input type="text" id="from"/>
<select id="locale">
<option value="af">Afrikaans</option>
<option value="sq">Albanian (Gjuha shqipe)</option>
<option value="ar-DZ">Algerian Arabic</option>
<option value="ar">Arabic (‫(لعربي</option>
<option value="hy">Armenian (Հայերեն)</option>
<option value="az">Azerbaijani (Azərbaycan dili)</option>
<option value="eu">Basque (Euskara)</option>
<option value="bs">Bosnian (Bosanski)</option>
<option value="bg">Bulgarian (български език)</option>
<option value="ca">Catalan (Català)</option>
<option value="zh-HK">Chinese Hong Kong (繁體中文)</option>
<option value="zh-CN">Chinese Simplified (简体中文)</option>
<option value="zh-TW">Chinese Traditional (繁體中文)</option>
<option value="hr">Croatian (Hrvatski jezik)</option>
<option value="cs">Czech (čeština)</option>
<option value="da">Danish (Dansk)</option>
<option value="nl-BE">Dutch (Belgium)</option>
<option value="nl">Dutch (Nederlands)</option>
<option value="en-AU">English/Australia</option>
<option value="en-NZ">English/New Zealand</option>
<option value="en-GB">English/UK</option>
<option value="eo">Esperanto</option>
<option value="et">Estonian (eesti keel)</option>
<option value="fo">Faroese (føroyskt)</option>
<option value="fa">Farsi/Persian (‫(فارسی</option>
<option value="fi">Finnish (suomi)</option>
<option value="fr" selected="selected">French (Français)</option>
<option value="fr-CH">French/Swiss (Français de Suisse)</option>
<option value="gl">Galician</option>
<option value="ge">Georgian</option>
<option value="de">German (Deutsch)</option>
<option value="el">Greek (Ελληνικά)</option>
<option value="he">Hebrew (‫(עברית</option>
<option value="hi">Hindi (हिंदी)</option>
<option value="hu">Hungarian (Magyar)</option>
<option value="is">Icelandic (Õslenska)</option>
<option value="id">Indonesian (Bahasa Indonesia)</option>
<option value="it">Italian (Italiano)</option>
<option value="ja">Japanese (日本語)</option>
<option value="kk">Kazakhstan (Kazakh)</option>
<option value="km">Khmer</option>
<option value="ko">Korean (한국어)</option>
<option value="lv">Latvian (Latvieöu Valoda)</option>
<option value="lt">Lithuanian (lietuviu kalba)</option>
<option value="lb">Luxembourgish</option>
<option value="mk">Macedonian</option>
<option value="ml">Malayalam</option>
<option value="ms">Malaysian (Bahasa Malaysia)</option>
<option value="no">Norwegian (Norsk)</option>
<option value="pl">Polish (Polski)</option>
<option value="pt">Portuguese (Português)</option>
<option value="pt-BR">Portuguese/Brazilian (Português)</option>
<option value="rm">Rhaeto-Romanic (Romansh)</option>
<option value="ro">Romanian (Română)</option>
<option value="ru">Russian (Русский)</option>
<option value="sr">Serbian (српски језик)</option>
<option value="sr-SR">Serbian (srpski jezik)</option>
<option value="sk">Slovak (Slovencina)</option>
<option value="sl">Slovenian (Slovenski Jezik)</option>
<option value="es">Spanish (Español)</option>
<option value="sv">Swedish (Svenska)</option>
<option value="ta">Tamil (தமிழ்)</option>
<option value="th">Thai (ภาษาไทย)</option>
<option value="tj">Tajikistan</option>
<option value="tr">Turkish (Türkçe)</option>
<option value="uk">Ukranian (Українська)</option>
<option value="vi">Vietnamese (Tiếng Việt)</option>
<option value="cy-GB">Welsh/UK (Cymraeg)</option>
</select></p>
</body></html>
参考文献:
答案 1 :(得分:3)
好吧,我花了将近一整天的时间才能让我的jQuery DatePicker进行本地化:
步骤1:在一个公共文件中为所有语言(您希望翻译出现的所有语言)创建一个包含所有月份名称翻译的JS文件,并将其命名为 jquery .ui.datepicker-common.js (或者你喜欢什么) (您可以为所有必需的语言创建单独的JS文件,并将其命名为 - jquery.ui.datepicker-fr.js for French File)
第2步:在网页中包含此JS文件,您希望在其中显示已翻译的值。
<script src="Assets/JS/JQuery/jquery.ui.datepicker-fr.js" type="text/javascript"></script>
第3步:请按照此示例使DatePicker使用翻译后的语言。
将您的日期选择器名称粘贴到DatePickerName
。
将您当前语言的控件名称粘贴到hdn_Locale
中(如示例中所用)。
$("#DatePickerName").datepicker({
changeMonth: true,
changeYear: true,
defaultDate: "+4w",
minDate: "+1d",
dateFormat: "yy/mm/dd",
onSelect: function (selectedDate) {
$("#DatePickerName").datepicker(navigator.userLanguage,
$.datepicker.regional[$('#hdn_Locale').val()]);
}
});
答案 2 :(得分:0)
我设法得到这个工作我已经将jquery ui中的语言包装在选择部分上,这已经不再需要了,因为我已经声明了dateformat和mindate选项以前在一切正常工作之后启用了代码
<script type="text/javascript">
//<![CDATA[
$(function() {
$.datepicker.setDefaults( $.datepicker.regional[ "" ] );
$( "#from" ).datepicker({
defaultDate: "+4w",
changeMonth: true,
numberOfMonths: 2,
showButtonPanel: true,
showOn: "button",
buttonImage: "../images/calendar.gif",
buttonImageOnly: true,
minDate:"+1d",
dateFormat:"yy/mm/dd",
showAnim:"blind",
});
$( "#from" ).datepicker( $.datepicker.regional[ "en-GB" ] );
$( "#locale" ).change(function() {
$( "#from" ).datepicker( "option",
$.datepicker.regional[ $( this ).val() ] );
});
$( "#to" ).datepicker({
defaultDate: "+2w",
changeMonth: true,
numberOfMonths: 2,
showButtonPanel: true,
showOn: "button",
buttonImage: "../images/calendar.gif",
buttonImageOnly: true,
minDate:"",
dateFormat:"yy/mm/dd",
showAnim:"blind",
});
$( "#to" ).datepicker( $.datepicker.regional[ "en-GB" ] );
$( "#locale" ).change(function() {
$( "#to" ).datepicker( "option",
$.datepicker.regional[ $( this ).val() ] );
});
});
//]]>
</script>