admin管理员组

文章数量:1300061

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

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

Share Improve this question asked Aug 27, 2013 at 12:31 Nithin ViswanathanNithin Viswanathan 3,2837 gold badges44 silver badges85 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

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
}));

Here's a simple way (see this JFiddle: http://jsfiddle/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()]);
    });
});

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

See: http://jqueryui./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./ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery./jquery-1.9.1.js"></script>
  <script src="http://code.jquery./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>

本文标签: javascriptLanguage translation in jquery date pickerStack Overflow