Language translation in jquery date picker

*爱你&永不变心* 提交于 2021-02-07 12:48:17

问题


How can I include both language translation and changeMonth and changeYear options together in jquery date picker. For that I used the below code For Language translation

$(this).datepicker($.datepicker.regional['fr']);

For ChangeYear

$( this ).datepicker({
      changeMonth: true,
      changeYear: true
    });

I want to run these two in a single datepicker box.Please help


回答1:


Looking at the source the regional is an object with options so this should work:

$(this).datepicker($.extend({}, $.datepicker.regional['fr'], {
  changeMonth: true,
  changeYear: true
}));



回答2:


Here's a simple way (see this JFiddle: http://jsfiddle.net/Kp8Nq/). You can change the localization option instead of creating a new datepicker:

$(function () {
    $("#datepicker").datepicker({
      changeMonth: true,
      changeYear: true
    });
     $("#datepicker").datepicker("option",
        $.datepicker.regional["fr"]);

    $("#locale").change(function () {
        $("#datepicker").datepicker("option",
        $.datepicker.regional[$(this).val()]);
    });
});



回答3:


I personally would let the user decide, if you have a multi-national website:

See: http://jqueryui.com/datepicker/#localization

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>jQuery UI Datepicker - Localize calendar</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <script src="jquery.ui.datepicker-ar.js"></script>
  <script src="jquery.ui.datepicker-fr.js"></script>
  <script src="jquery.ui.datepicker-he.js"></script>
  <script src="jquery.ui.datepicker-zh-TW.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <script>
  $(function() {
    $( "#datepicker" ).datepicker( $.datepicker.regional[ "fr" ] );
    $( "#locale" ).change(function() {
      $( "#datepicker" ).datepicker( "option",
        $.datepicker.regional[ $( this ).val() ] );
    });
  });
  </script>
</head>
<body>

<p>Date: <input type="text" id="datepicker" />&nbsp;
  <select id="locale">
    <option value="ar">Arabic (‫(العربية</option>
    <option value="zh-TW">Chinese Traditional (繁體中文)</option>
    <option value="">English</option>
    <option value="fr" selected="selected">French (Français)</option>
    <option value="he">Hebrew (‫(עברית</option>
  </select></p>


</body>
</html>


来源:https://stackoverflow.com/questions/18465518/language-translation-in-jquery-date-picker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!